hello, I instantiate 50 objects. I want to be able to differentiate them after this. how can I mark them individually?
Thanks!
Well, there are a few ways of doing this…
- Add them to a List. Example:
- `public class Whatever{
public List MyList = new List();
private void MakeStuff()
{
//Do your loop or whatever here…and put this inside:
GameObject go = Instantiate(OneOf50, blah, blah, blah);
MyList.Add(go);
}
}
`
Option 2: is to use: int i = 1; GameObject go = Instantiate(OneOf50, blah, blah, blah); go.Name = "Whatever "+ i; i++;
That’ll make your opjects with the name of: Whatever 1, Whatever 2, Whatever 3, etc.
The BEST is to use the List. As Option 2 is kind of sketchy, but you’d use: GameObject.Find(“Whatever 3”); etc.
so I did that but one more problem appeared. I check if distance between this object and example cube is 5 and object name is “example” my cube does not recognizes it. I tried just name but it still does not work.
GameObject ga_bact = (GameObject)Instantiate(bacteria, transform.position = new Vector3(x2, y2, 0), transform.rotation); ga_bact.name = "example";
than
if (Vector3.Distance(ga.transform.position, gameObject.transform.position) < 5 && ga.name=="example){
}