Author Topic: Changing sprite using animator  (Read 2115 times)

TerraCo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Changing sprite using animator
« 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Changing sprite using animator
« Reply #1 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...