- Home /
Building Tilemap Animations in code require AnimationController
I am building a Tiled.org TMX parser (I know there are ones that exist and I'm using one of them, but I'm extending it to allow for Tiled animations) and I've run into a problem where I cannot programmatically create an Animation Controller.
Let's say I have the following snippet of code:
Animator newAnimator = (Animator)tilePrefabObj.AddComponent<Animator> ();
newAnimator.runtimeAnimatorController = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate (Resources.Load ("Artwork/Sprites/sprite_0"));
SpriteRenderer sr = tilePrefabObj.AddComponent<SpriteRenderer> ();
SourceData sd = gid2sprite [tileGID.Value];
Sprite source = (Sprite)sprites.First (s => s.name.Equals (sd.spriteName));
sr.sprite = source;
sr.sortingOrder = 0;
sr.color = new Color (1, 1, 1, 1.0f);
This works just fine and I can see that my prefab contains the Animator
component and that its Runtime Animation Controller
is set to the sprite_0
prefab.
What if I want to reference multiple sprites and create an Animation Controller programmatically and set the runtimeAnimationController
to that instead -- rather than use an existing Resource that already exists?
I can't find any documentation on creating a simple Animation Controller that contains a handful of different sprites in order to create an animated sprite.
Your answer
Follow this Question
Related Questions
why I have to anim.getComponent in update() function when I had done in Start () function 2 Answers
How can I create a home position where my character returns to after every animation? 0 Answers
How can I change my AnimatorState instantly? 1 Answer
Animation Mecanim - Parts of model displaces after animating 0 Answers
Animator.CrossFade or Animator.CrossFadeInInFixedTime does not play animation after crossfading. 0 Answers