I’m quite new to Unity and I have this code to play the attack animation when mouse is clicked, but it only happens once. For the first time it happens nicely, but the second time i press the mouse button nothing happens.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Animate : MonoBehaviour {
public Animator anim;
private bool attacked;
// Use this for initialization
void Start () {
anim.Play(“Idle”);
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.Mouse0)){
attacked= true;
}
if(attacked){
anim.Play (“Attack”);
attacked=false;
}
}
}