counting instances of an object
I have an object that is attached to a prefab which has a script that runs the following code on start:
for (int i = 0; i < 500; i++)
{
Instantiate(prefab, new Vector3(i *(Random.Range(-1f, 1f)), 0, (Random.Range(50f, 750f))), Quaternion.identity);
}
I then have a UI text object that I want to display the number of instances of the above object using:
count = GameObject.FindGameObjectsWithTag("Cube").Length;
countText.text = count.ToString("0");
however the count is only returning the number of objects (1) rather than the number of instances (500).
I've looked around at previous posts and they all seem to suggest that the answer can be obtained with the code I'm using so I must be doing something wrong and cannot say what it is.
From what I can understand reading the unity documentation the instanstiate method creates a copy of the object, and having proven that my code works when I manually duplicate the object I would have thought that this should be simple.
Can anybody help me? Thanks in advance. James
Your answer
Follow this Question
Related Questions
HELP --- Object reference not set to instance of an object. 0 Answers
Having problems with custom objects in my array - BCE0019 0 Answers
Unity Merging Objects 0 Answers
Why doesn't my object move when I use transform.position? 0 Answers
object in Hierarchy does not show up in scene and game 0 Answers