Hello. I want my player to be able to punch when he uses the Mouse0 key but the animation doesn’t play and I don’t know why.
I’m using this script:
public class Punch : MonoBehaviour
{
private bool playerClicked;
Animation anim;
void Start ()
{
anim = GetComponent<Animation>();
}
void Update ()
{
Punching();
}
void Punching()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
playerClicked = true;
}
if(Input.GetKeyUp(KeyCode.Mouse0) && playerClicked == true)
{
anim.Play("Punch");
}
}
}