Есть задача:
Дожно быть:
при первом нажатии - должна воникнуть башня №1 и потратиться 50 золота
при втором нажатии - должна воникнуть башня №2 и потратиться ещё 50 золота
На практике: если есть 100 золота при первом нажатии возникает башня №2, если 50 золота, то башня №1
при втором нажатии - ничего не происходит
Просьба подсказать
Синтаксис:
Используется csharp
public GameObject Tower1;
public GameObject Tower2;
public Vector3 offset;
public GameObject curTower;
int empty = 0;
public GameObject Controller;
void Update()
{
Controller = GameObject.Find("Main Camera");
}
void OnMouseDown()
{
if (empty == 0 && Controller.GetComponent<GameController>().Gold >= 50)
{
curTower = GameObject.Instantiate(Tower1, transform.position + offset, Quaternion.identity) as GameObject;
empty = 1;
Controller.GetComponent<GameController>().Gold -= 50;
}
if (empty == 1 && Controller.GetComponent<GameController>().Gold >= 50 )
{
Destroy(curTower);
curTower = GameObject.Instantiate(Tower2, transform.position + offset, Quaternion.identity) as GameObject;
empty = 2;
Controller.GetComponent<GameController>().Gold -= 50;
}
}
}
public GameObject Tower2;
public Vector3 offset;
public GameObject curTower;
int empty = 0;
public GameObject Controller;
void Update()
{
Controller = GameObject.Find("Main Camera");
}
void OnMouseDown()
{
if (empty == 0 && Controller.GetComponent<GameController>().Gold >= 50)
{
curTower = GameObject.Instantiate(Tower1, transform.position + offset, Quaternion.identity) as GameObject;
empty = 1;
Controller.GetComponent<GameController>().Gold -= 50;
}
if (empty == 1 && Controller.GetComponent<GameController>().Gold >= 50 )
{
Destroy(curTower);
curTower = GameObject.Instantiate(Tower2, transform.position + offset, Quaternion.identity) as GameObject;
empty = 2;
Controller.GetComponent<GameController>().Gold -= 50;
}
}
}
Заранее спасибо