I want to instantiate a single gameobject every 6th second, generating a total of 5 gameobjects per minute. The seconds and minutes are referred from another script called “controller”. This is the code i have, but instead of a single object, each time numerous gameobjects are generated. I don’t know what is wrong with the script, any pointers would be highly appreciated! Thanks
public int count=5;
public int timeinterval=6
Void Update(){
firstmin();
}
void firstmin(){
for (int i = 0; i < count; i++) {
if (Controller.minutes==1 && Controller.seconds!=0 && Controller.seconds % timeinterval == 0) {
Vector3 pos = new Vector3 (this.transform.position.x, this.transform.position.y,
this.transform.position.z);
GameObject starinstance;
starinstance = Instantiate (star, pos, star.transform.rotation);
}
}
}