I need help with this script:
public Animator anim;
public GameObject Projectile;
void Update()
{
if (Input.GetAxisRaw("Horizontal") == 0)
{
if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
{
anim.SetFloat("Speed", 2f);
Instantiate(Projectile, attackPos.position, Quaternion.identity);
Invoke("Switch", .5f);
}
}
else
{
anim.SetFloat("Speed", Input.GetAxisRaw("Horizontal"));
}
}
void Switch()
{
anim.SetFloat("Speed", Input.GetAxisRaw("Horizontal"));
}
This script does what I want but whenever I stop moving and have not pressed S or down arrow to attack I stay in the walk Animation forever until I attack again. Also I want the character to stop moving before it attacks(and it is a platformer if that matters)