- Home /
How to count instantiated objects that passes a given point (transform.position.y)
My instantiated objects move up and user touch to destroy them. I want to count intantiated objects that passes a spesific point. (i want to count how many objects user missed ) So that when counting number reaches a detirmined number, the game will be over. Could please help, What 's wrong with my script.
public GameObject[] obj;
void Update() { for (int i = 0; i < obj.Length; i++) { if (obj[i].transform.position.y> 4)
{ countObj(1); //Counting object funtion } } }
Answer by DrMobile · Jan 18, 2018 at 10:19 AM
public GameObject[] obj;
void Update()
{
for (int i = 0; i < obj.Length; i++)
{ if (obj[i].transform.position.y> 4)
{ countObj(1); //Counting object funtion }
}
}
Your answer
Follow this Question
Related Questions
IndexOutOfRangeException: Array index is out of range when using an Array and instantiating 2 Answers
Array with game object: object reference not set to an instance of an object 1 Answer
Instantiating an array of objects - how can I instantiate a certain prefab only once? 1 Answer
Instantiate object in for loop with array 2 Answers
How can I naming each instantiated object in "for" loop ? 1 Answer