Hi everyone,
Wondering if it possible to access specified instantiated object, not right after instantiating,
for example I want to access enemy26, after enemy50 is already instantiated.
I guess I should give the Instantiated object a special definition while Instantiationg , and then I can call it from it special definition.
Thanks in advance.
Hi,
I think you should instantiate your all enemies into table, then call specific enemy from table;
I would do something like that:
Enemy[] enemies;
....
Enemy _enemy = Instantiate(enemy);
enemies[i]= _enemy;
i++;
...
enemies[26].ValueYouWantToChange= someValue;
Make sense.
Possible to change the[26] to some name of an object?
I mean for quick find what I want, find by name or something.
You could use a dictionary if you want a name to it
Sorry, What is Dictionary?
I would reccomend to go and check → List-> Dictionary, its similar to 2 dimensional table where first row is position second is name, but objects are stacked in queue so if you remove one from list all objecto comming after will get their postion -1,
Dictionary<string, GameObject> myDictionary = new Dictionary<string, GameObject>();
public void SomeMethod() {
// Let's instantiate Gary
GameObject instanceOfGary = Instantiate(GaryPrefab);
// Let's store Gary for later usage:
myDictionary["Gary"] = instanceOfGary;
}
public void ADifferentMethod() {
// Hey what happened to that Gary we created before? I need him
GameObject theGaryFromBefore = myDictionary["Gary"];
// I never much liked Gary
Destroy(theGaryFromBefore);
}
This is very nice.
Thank you.