Hello,
I am trying to write a script to spawn a game object for every 5 coins collected.
I have the spawn working when I collect the first 5 coins. The problem is as long as coinsCollected = 5 then I get multiple spawns because start Spawn code is in Update. As soon as I collect another coin then coinsCollected does not = 5 so the spawning stops. How do I ad a variable or int for C# so the spawing stops immediately.
Also how would I make my script work so that every 5 coins collected a game object will spawn. The game object spawning is always going to be the same game object(like a power up).
Thanks in Advance.
Here is my code:
public GameObject obj;
public Vector3 spawnValues;
private PlayerMove playerMove;
private GUIManager gui;
int myInt = 1;
void Start ()
{
playerMove = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMove>();
gui = FindObjectOfType(typeof(GUIManager)) as GUIManager ;
transform.position = playerMove.transform.position;
}
void Update ()
{
if (gui.coinsCollected == 5){
Spawn();
}
}
void Spawn ()
{
Instantiate(obj, transform.position, Quaternion.Euler(Vector3.zero));
//Instantiate
}
}