I want to locate an animator in a child of the current gameobject the script is attached to. My Gameobject is player, inside the player there are skins that are disabled when other skins are enabled, every skin has an animator, I want to reference the first animator of the active player skin object.
I want to get an animator from any active skin (which are children of player) from my player gameobject
sorry if this is too complicated to understand.
I am aspecting that you have only skins with animator type of game objects as children for your player. If this is the case then you can do this.
Your player game object has a Transform component. So you can loop through all the children in this transform like this.
for(t = 0; t < transform.childCount; t++)
Transform childTrans = transform.GetChild(t); //This will return child transform.
//Check if this childTrans game object is active or not.
//If this childTrans game object is active (skin), then you can get animator component of it.
Animator animator = childTrans.GetComponent<Animator>();
//Do your stuff with animator and you can break this loop here.
Hope this will help.