- Home /
Question by
Eco-Editor · Jul 09, 2018 at 08:09 PM ·
animatortriggerlistindexinvokerepeating
How to play animation from an array of gameObjects?
Hello all,
I have a list (or an array) of gameobjects with the Animator component. My goal is to setTrigger on each gameObject, such that the trigger happens each 10 seconds. this is my script so far:
//public List<Animator> enemies = new List<Animator>(); //or a list
public Animator[] anim;
private void Start()
{
anim = GetComponentsInChildren<Animator>();
/*foreach (Transform t in transform) //in case of a list
{
enemies.Add(t.GetComponentInChildren<Animator>());
InvokeRepeating("SpawnEnemy", 10, 10);
}*/
}
private void SpawnEnemy()
{
for (int i = 0; i < anim.Length; i++)
{
anim[i].SetTrigger("FadeIn");
}
/*for (int i = 0; i < enemies.Count; i++) //in case of a list
{
enemies[i+1].SetTrigger("FadeIn");
}*/
currently this code returns null reference
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612170353im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Animator Trigger Not Working 1 Answer
Get Animator parameter index by name 1 Answer
2D Animation does not start 1 Answer