Right, so I have 2 animations for a gun aiming. When I right click, the sights of the gun line up, and in the script the bool “gunAiming” becomes true. When it becomes true, and I right click again, the animation of the gun returning to it’s original spot must be played and the bool will become false again. But the problem is that only the return animation is playing, and not the first aiming animation. Now, I think the problem is that the bool “gunAiming” becomes true immediately after pressing right-mouse button. So I think that the solution would be for the bool to become true once it detects that the animation ended. If that is not the problem, please provide another solution. Also, an in-depth explanation of what is happening in the script would be helpful. Here is the script:
public bool gunAiming = false;
void Update () {
if (Input.GetKey (KeyCode.Mouse1) && !gunAiming) {
GetComponent<Animation>().Play ("aim");
gunAiming = true;
}
if (Input.GetKey (KeyCode.Mouse1) && gunAiming) {
GetComponent<Animation> ().Play ("returnaim");
gunAiming = false;
}
}