- Home /
Question by
GrandWaazoo · Mar 02, 2014 at 06:19 PM ·
2danimatoranimator controller
Dynamic animator(2D) array Unity4.3
Hello !
I'm working on a project with unity 4.3, I work with the 2d module and i'm coding with C#. I want to create a class which contains some animations generated by the module Animator of Unity, and I want play one of these. I have a class which contains a public array of RuntimeAnimatorController, I create an Animator for each RuntimeAnimatorController in the array.
public class CreateATrap : MonoBehaviour {
public Sprite[] trapSprite;
public RuntimeAnimatorController[] trapAnimation;
private Animator[] trapAnimator;
private Sprite CurSprite;
private Animator CurAnimation;
private SpriteRenderer myRenderer;
private bool timeStarted = false;
private float timer = 0;
private float maxTimer = 0;
private int currText;
// Use this for initialization
void Start () {
int i = 0;
myRenderer = gameObject.GetComponent<SpriteRenderer>();
trapAnimator = new Animator[trapAnimation.Length];
foreach (Animator element in trapAnimator)
{
element.runtimeAnimatorController = new RuntimeAnimatorController();
element.runtimeAnimatorController = trapAnimation[i];
++i;
}
}
}
I have some trouble to apply my method, Unity doesn't like this. And I don't even know if I can do something like this ...
Thank you in advance for your help
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613135203im_/https://answers.unity.com/themes/thub/images/avi.jpg)