Animated Sprite Usage

Hey guys im a but confused as to how to create and utilize sprites in Unity. I can’t seem to find a clear source of information online.

Let’s say i download this png.
http://opengameart.org/sites/default/files/zombie_topdown.png

Now i import it into unity, select sprite mode: multiple, and manually cut each zombie image.

Can that work, or do i need to have every type of animation as a separate sprite with option sprite mode: multiple?

How can i specify for the gameObject to play the “walking” animation when a zombie is walking, play “dying” animation when it gets hit?

In the classic 3D animator things were simple, u just have a different clips and u basically do animator.play(), but with this sprite stuff im confused.

UPDATE: OH ONE MORE QUESTION!

I see in the sprite sheet all the different orientations of zombies (upleft up upright right downright down downleft left)

I don’t understand why that’s necessary, can we just rotate by script one version of the sprite to achieve the right direction, or is doing it this way much more convenient somehow? can someone please explain how, thanks :slight_smile:

There are two Animation Controller Components built into Unity.

The first is the Animation component. That is the one that allows animation.play(“animationName”). It, unfortunately, is legacy now and doesn’t support the new sprite “dope sheet” animation.

The second component is the Animator component. The Animator component is more robust, but also more complicated. If your animation is tied to an Animator component, then you can use the Dope Sheet in the Animation window. That gives you the desired type of animation.

You can roughly replicate the Animation component’s animation.play(“animationName”) functionality with the Animator component. To do this, in the animation controller, create a state and a trigger for each animation. Then, create transitions with the triggers from the special “ANY” state to the state for the animation you want to trigger. Then, you can play the animation like this.

getComponent<Animator>().SetTrigger("animationTriggerName");

for more information on how to use the Animator, look HERE.

Add Sprite sheet or Single Sprites to unity project and

for animation you have to use your own script i am sharing that script below

var uvAnimationTileX = 24; //Here you can place the number of columns of your sheet.      
var uvAnimationTileY = 1; //Here you can place the number of rows of your sheet. 
var framesPerSecond = 10.0;
 
function Update () {
 
	// Calculate index
	var index : int = Time.time * framesPerSecond;
	// repeat when exhausting all frames
	index = index % (uvAnimationTileX * uvAnimationTileY);
 
	// Size of every tile
	var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
 
	// split into horizontal and vertical index
	var uIndex = index % uvAnimationTileX;
	var vIndex = index / uvAnimationTileX;
 
	// build offset
	// v coordinate is the bottom of the image in opengl so we need to invert.
	var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
 
	renderer.material.SetTextureOffset ("_MainTex", offset);
	renderer.material.SetTextureScale ("_MainTex", size);
}

And for single sprites

var frames : Texture2D[];
var framesPerSecond = 10.0;

function Update () {
    var index : int = Time.time * framesPerSecond;
    index = index % frames.Length;
    renderer.material.mainTexture = frames[index];
}

Hope This is helpful for you…