Canvas element animations

I am using a canvas for a battle system. and I have sprite sheets with the frames of my animations for my character.
for normal objects, you can just drag and drop the sprite sheet into the editor, and it will automatically generate an animation with the frames. however, it doesn’t do this with UI images, it does this with sprite 2Ds, I have long animations, and I don’t want to input it manually. is there a way to do it automatically? or to change the autogenerated keyframes to use UI image instead of sprite2d?

You could probably get it working ultra-cheese by just dragging and instance of your animated sprite into the scene, moving it far away from where any camera can see it, then having a cheeseball script to copy the Sprite FROM the animated SpriteRenderer (being driven by the looping animation) over TO the UI.Image.

Lol, Unity is so easy to do this stuff. It took like two minutes to prove. Here you go:

using UnityEngine;
using UnityEngine.UI;

// @kurtdekker
// intended to copy the .sprite field from an animated
// SpriteRenderer over to a UI.Image field.

public class SpriteAnimationMimicker : MonoBehaviour
{
	[Header("FROM: The SpriteRenderer being animated.")]
	public SpriteRenderer spriteRenderer;

	[Header("TO: The target UI.Image you want to update.")]
	public Image image;

	void LateUpdate ()
	{
		image.sprite = spriteRenderer.sprite;	
	}
}

1 Like