Hello
i am making some codes in c# to instantiate a Gameobject but i want to know the name or tag of the instantiated object
so i can use
if (gameobject.name == "the instantiated object")
//do something
is there anyway to do it?
Hello
i am making some codes in c# to instantiate a Gameobject but i want to know the name or tag of the instantiated object
so i can use
if (gameobject.name == "the instantiated object")
//do something
is there anyway to do it?
try this
if(gameObject.name.Equals("YourGameObject")){
//do something
}
or use tag
if(gameObject.tag.Equals("YourGameObject")){
//do something
}
I would create a temp variable that allows you to assess it instead of looking for it after the fact.
GameObject clonePrefab = Instantiate(prefabObject,transform.position,Quaternion.identety) as Gameobject
clonePrefab.name = "new object's name"
clonePrefab.tag = "objectstag"
WUCC
i just did Clone.name and it worked :D Thank you anyway ^^ also what does Equals do?
– ShnayzrEquals and == do pretty much the same thing, with the exception that Equals is more flexible. You can do things like tell it to ignore case, for example. Here is a link to the MSDN about the version of string.Equals that allows for that: [http://msdn.microsoft.com/en-us/library/c64xh8f9(v=vs.110).aspx][1] [1]: http://msdn.microsoft.com/en-us/library/c64xh8f9(v=vs.110).aspx
– Habitablaba