zeuo
February 7, 2011, 3:08am
1
so how to access scripts in children dos anyone know in a child there is a script called enemy and in enemy there is a var called health anythone know how to change that from the parent
gameobject-->child-->script called enemy-->var in enemy called health
i just want the health = 100
system
February 7, 2011, 3:26am
3
There are a lot of ways to do this here are two:
Here is my preferred method (only if the script you are looking for occurs only once in the children)
enemy myscript = gameObject.GetComponentInChildren();
enemy.health = 90;
This is a little bit more specific method (specifies the child gameobjects name)
enemy myscript = GameObject.Find("child").GetComponent();
enemy.health = 90;
[Edited] to show symbols
Learn more here:
http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
tertle
February 7, 2011, 3:16am
2
Accessing components - for scripts on the same object
Accessing game objects - for scripts on a different object
Or maybe slightly more relevant
GetComponentInChildren