- Home /
Fetching Objects that belongs to other script, with name or tag
Hi. I believe my question should have been asked before but somehow I can not find the answer after a good amount of research. What I want to do is to get a specific object by its name (or tag) that belongs to another script/object.
GameObject go = GameObject.Find("SomeGuy");
This doesnt work since the object named "SomeGuy" is located in some other object. I tried
go = GameObject.FindWithTag("myTag").GetComponent(OtherScript) as OtherScript;
This gives error.
go = FindObjectOfType(typeof(OtherScript)) as OtherScript;
This brings any object belongs to that class / script
However I am looking for a specific object with a name or a tag. What is the best way to accomplish what I want. Thank you.
Answer by yigitcan · Jan 17, 2012 at 12:23 PM
Dont know if its OK to answer my own question like this but heres the answer:
go = GameObject.Find("myName").GetComponent(typeof(OtherScript)) as OtherScript;
Your answer
Follow this Question
Related Questions
Same script not working on all objects 1 Answer
Object doesn't stick on Camera right Corner?? (Basic Question) 1 Answer
Drag Script Not Working 1 Answer
How to draw GUI Text from code 1 Answer
ngui health bar in multiplayer game? 0 Answers