An error occurred while loading the file. Please try again.
-
Raffael Di Pietro authored9474f2bb
Forked from
Chirz / CityEscape
180 commits behind the upstream repository.
GenerateMap.cs 3.17 KiB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenerateMap : MonoBehaviour
{
public Item chaussures;
public Item baton;
public Item rechaud;
public Item tente;
public GameObject GO_chaussures;
public GameObject GO_baton;
public GameObject GO_rechaud;
public GameObject GO_tente;
public List<GameObject> pVillage = new List<GameObject>();
public List<GameObject> pBoutique = new List<GameObject>();
public List<GameObject> pUsine = new List<GameObject>();
public int nb_of_plot = 8;
public Object[,] plot=new Object[3,3];
//Les coordonées x dans l'ordre
private int[] xs=new int[]{-17,0,17}; //colonne
//Les coordonées y dans l'ordre
private int[] ys=new int[]{26,13,0}; //ligne
// Start is called before the first frame update
void Start()
{
generateVillage();
}
//Place les 8 prefabs aux bons endroits
public void generateVillage()
{/*
for (int i=0;i< nb_of_plot; i++)
{
plot[i] = Instantiate(pVillage[Random.Range(0, pVillage.Count)], new Vector3(xs[i], ys[i], 0), Quaternion.identity);
}*/
for(int x = 0; x < xs.Length; x++)
{
for(int y = 0; y<ys.Length; y++)
{
if(!(x==2 && y==2))
plot[x,y] = Instantiate(pVillage[Random.Range(0, pVillage.Count)], new Vector3(xs[x], ys[y], 0), Quaternion.identity);
}
}
}
public void generateBoutique(int column, int line, string objetVente)
{
Destroy(plot[column, line]);
Item itemToSell = null;
GameObject goToSell = null;
switch (objetVente)
{
case "chaussure":
itemToSell = chaussures;
goToSell = GO_chaussures;
break;
case "baton":
itemToSell = baton;
goToSell = GO_baton;
break;
case "réchaud":
itemToSell = rechaud;
goToSell = GO_rechaud;
break;
case "tente":
itemToSell = tente;
goToSell = GO_tente;
break;
}
if (itemToSell && goToSell)
{
GameObject shop = Instantiate(pBoutique[Random.Range(0, pBoutique.Count)], new Vector3(xs[column], ys[line], 0), Quaternion.identity);
shop.transform.Find("Shop").gameObject.GetComponent<Shopping>().sellItem = itemToSell;
shop.transform.Find("Shop").gameObject.GetComponent<Shopping>().itemForSale.Add(goToSell);
plot[column, line] = shop;
}
else
Debug.LogError("Mauvais paramètre pour objetVente");
}
public void generateUsine(int column, int line)
{
Destroy(plot[column, line]);
plot[column, line] = Instantiate(pUsine[Random.Range(0, pUsine.Count)], new Vector3(xs[column], ys[line], 0), Quaternion.identity);
}
public void generateBoutiqueTest()
{
// COLONNE, LIGNE
generateBoutique(0, 0, "chaussure");
generateUsine(1, 0);
}
void Update()
{
}
}