- Home /
Animated Sprite in UI Canvas?
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.
Tips appreciated! :) Thanks
$$anonymous$$aybe there's a unity script now, but we just had a script that iterated through a bunch of images, assigning them to the Image. Its probable SpriteRenderer is legacy, and doesn't work with the ugui.
Thanks for the answer. I know I could code something up in a script that does it manually, but I was hoping I could use the animation tools that Unity offers, just for convenience. It seems unlikely that the Sprite Renderer is legacy, since it hasn't been that long since all the 2D stuff was introduced, afaik.. But perhaps it was never meant to be used in combination with the UI system (?).
Bump? This has been bugging me as well... Find an answer to this?
I currently have a UI Image animating with an Animator, but I have another UI Image in the same canvas that just won't animate. It makes no sense.
Edit: Just made the sprites smaller, and now it animates.
Answer by hersheys72 · Jan 06, 2016 at 05:21 AM
To change from a sprite to an animation you have to follow the steps found at :
http://answers.unity3d.com/questions/931917/animate-image-ui-with-sprite-sheet.html
Answer by HappySaila · Jan 28, 2016 at 01:27 PM
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[i];
yield return new WaitForSeconds(animationSpeed);
}
}
}
oh,,, animationSpeed/sprites.Length, this will end the animation on your desired time.
Answer by legendbone · Jan 05, 2015 at 10:16 AM
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.
Answer by piyusnitnware · Dec 02, 2016 at 08:17 AM
Create an empty UI game object and make child your animated sprites to newly created UI gameObject. Now you can use it anywhere in your UI.
This works for me.
Your answer
Follow this Question
Related Questions
Unity 4.6: How to fit center byte array png in the Image UI? 1 Answer
4.6 play animation on game over 0 Answers
Best way to change sprite in Image (GUI 4.6) ? 1 Answer
Set active button after sprite animation. 0 Answers
Loading built-in resources 1 Answer