Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: TerraCo on August 14, 2014, 11:11:03 PM

Title: Changing sprite using animator
Post by: TerraCo on August 14, 2014, 11:11:03 PM
Hi,

I am trying to change sprites in an object at certain points during an animation. Imagine Street Fighter with each body part being a different sprite.

The only way I have been able to do it is through code, which is a nightmare for my animator as he has to run the game each time he wants to see a change.

Is there a way to update the sprite in an animation?

Thanks,

Terraco
Title: Re: Changing sprite using animator
Post by: ArenMook on August 15, 2014, 07:41:13 AM
Yup, create an intermediate script and animate its value.
  1. using UnityEngine;
  2.  
  3. [ExecuteInEditor]
  4. [RequireComponent(typeof(UI2DSprite))]
  5. public class Sprite2DAnimator : MonoBehaviour
  6. {
  7.     public UnityEngine.Sprite sprite;
  8.  
  9.     UI2DSprite mSprite;
  10.  
  11.     void Awake () { mSprite = GetComponent<UI2DSprite>(); }
  12.  
  13.     void Update () { mSprite.sprite2D = sprite; }
  14. }
Edit: Although... I don't remember if that field will show up in the animator in 4.5...