I have a simple animation of up and down. So if i press and hold A, it goes down and stops whenever I release it.
private Animator Anim;
private bool flu = false;
void Start()
{
Anim = gameObject.GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
Anim.SetBool("flu", true);
Anim.speed = 1f;
}
else if (Input.GetKeyUp(KeyCode.A))
{
Anim.speed = 0;
}
But I wanted to make it go back aka reverse the animation when i press and hold S, and stops when I release it.
I tried:
private Animator Anim;
private bool flu = false;
void Start()
{
Anim = gameObject.GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
Anim.SetBool("flu", true);
Anim.speed = 1f;
}
else if (Input.GetKeyUp(KeyCode.A))
{
Anim.speed = 0;
}
else
{
if (Input.GetKeyDown(KeyCode.S) && flu)
{
Anim.speed = -1f;
}
else if (Input.GetKeyUp(KeyCode.S))
{
Anim.speed = 0;
}
}
}
But it didnt work, care to help?