Stop animation at any frame? or have two idle states?
So I'm trying to recreate the original Legend of Zelda for the NES in Unity but I'm having trouble with the sprite's walking and idle states.
In the game there are only two frames used for the walking animation, but both of them can be idle states as once the player stops input the sprite stops at whatever frame it was. I managed to replicate this using animator.enabled = false;
when there is no input. But when i went to do the attack animation it only works when there is directional input and not when standing still.
So is there a way to cycle between the two walking frames when there is input and use them both as idle states when there is none?
My code so far:
using UnityEngine;
using System.Collections;
public class Link : MonoBehaviour {
private Animator animator;
// Use this for initialization
void Start ()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
int horizontal = (int) Input.GetAxisRaw("Horizontal");
int vertical = (int) Input.GetAxisRaw("Vertical");
if (horizontal > 0)
{
animator.SetInteger("Direction", 3); //Link faces East
// animator.enabled = true;
}
else if (horizontal < 0)
{
animator.SetInteger("Direction", 1); //Link faces West
// animator.enabled = true;
}
else if (vertical > 0)
{
animator.SetInteger("Direction", 2); //Link faces North
//animator.enabled = true;
}
else if (vertical < 0)
{
animator.SetInteger("Direction", 0); //Link faces South
//animator.enabled = true;
}
else if (Input.GetButtonDown("Fire1"))
{
animator.SetTrigger("Attack");
// animator.enabled = true;
}
else
{
//animator.enabled = false; // stops walking animation when key is not being pressed
}
}
}
Your answer
Follow this Question
Related Questions
Animating Sprites Through Separate Script? 0 Answers
How do I apply an animation to a sprite? 0 Answers
Help with 8-DOM Weapon Sprite Issue 0 Answers
Attaching Armour 2D sprites 0 Answers
Sprite size while animating ? 1 Answer