I have a few mesh/models that share an Animator, these will not play simultaneously but since the animator must be on another GameObject I want to know if it is possible to assign the mesh/model that I want to animate.
Although they use the same animator, you can target the animator of the specific gameobject.
By specific name (for one gameobject):
GameObject temp = GameObject.Find("specific gameobject name");
temp.GetComponent<Animator>().setbool("play");
By contained phrase in name:
public List<GameObject> objToAnimate = new List<GameObject>();
GameObject[] allObj = GameObject.FindObjectsOfType(typeof(Monobehaviour));
foreach(GameObject tempObj in allObj){
if(tempObj.name.Contains("certain word in the name"){
objToAnimate.Add(tempObj);
}
}
if(objToAnimate.Count > 0){
foreach(GameObject temp in objToAnimate){
temp.GetComponent<Animator>().setbool("play");
}
}
By tag:
public List<GameObject> objToAnimate = new List<GameObject>();
GameObject[] allObj = GameObject.FindObjectsOfType(typeof(Monobehaviour));
foreach(GameObject tempObj in allObj){
if(tempObj.tag("tag name"){
objToAnimate.Add(tempObj);
}
}
if(objToAnimate.Count > 0){
foreach(GameObject temp in objToAnimate){
temp.GetComponent<Animator>().setbool("play");
}
}
If they all share the same animator you might want to use a “Animator Override Controller”.