Hope this isn’t too much of a noob question, but I can’t seem to find good information on it: I’d like to add an animated sprite (i.e. with proper Animation Controller) to a Unity 4.6 UI Canvas, but don’t quite know what’s the right way to do it. For static images I know to just add a UI->Image, but there’s no UI->Sprite. Is the combination of Sprite Renderer and Canvas Renderer even supported?
I tried adding an animation controller to a UI Image, but that didn’t play the animation. Then I tried removing the ‘Image’ component and adding a Sprite Renderer instead, which sort of works but not really (animation plays, but is displayed in scene view only, and the sprite is tiny). The same happens if I do it the other way around, start with a sprite and then add the Canvas Renderer.
What i basically did was change the sprites of an image on your GUI.
This code just plays like a 10 frame nuke bomb on the players hud
public class NukeScript : MonoBehaviour {
public Image image;
public Sprite[] sprites;
public float animationSpeed;
public IEnumerator nukeMethod()
{
//destroy all game objects
for (int i=0; i < sprites.Length; i++)
{
image.sprite = sprites*;*
yield return new WaitForSeconds(animationSpeed); } } }
You can set the canvas to screen space-camera ,then set an uicamera and pick the ui layer.but there cause another question :the canvas sort order is no longer working.