Newer
Older
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];
private int[] xs=new int[]{-17,0,17}; //colonne
private int[] ys=new int[]{26,13,0}; //ligne
public static GenerateMap instance;
private void Awake()
{
if (instance != null)
return;
instance = this;
}
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)
float xOffset = 0;
float yOffset = 0;
Item itemToSell = null;
GameObject goToSell = null;
switch (objetVente)
{
case "chaussure":
itemToSell = chaussures;
goToSell = GO_chaussures;
xOffset = 0;
yOffset = 6.1F;
break;
case "baton":
itemToSell = baton;
goToSell = GO_baton;
case "rechaud":
itemToSell = rechaud;
goToSell = GO_rechaud;
yOffset = 6.10F;
break;
case "tente":
itemToSell = tente;
goToSell = GO_tente;
xOffset = 2.7F;
yOffset = 2.27F;
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;
float x = shop.transform.position.x + xOffset;
float y = shop.transform.position.y + yOffset;
Instantiate(goToSell, new Vector3(x, y, 0), Quaternion.identity);
Debug.LogError("Mauvais paramètre pour objetVente: "+ 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, "rechaud");
generateBoutique(0, 1, "tente");
generateBoutique(1, 2, "baton");
generateBoutique(1, 1, "chaussure");