Animation Problem


Im currently working on a project that has aiming in it, so there are several animations, with run, walk, idle, reload being on layer 0, and aiming being on layer 1. Everything works fine but here's what I havent been able to do; when I press mouse button 1 i would like the character to play the aim animation, and when i click mouse button 1 again i'd like it to go back to the way it used to be, mixing stance, run, walk etc... The problem is because aim is on a higher layer, it always overlapses other animations. So my question is, how do I make the character go back to the original animations, without calling them directly?(because then the called animations overlapse other animations as well...)

Thank you for your answers

Sounds like you want to toggle the animation on-off. To do that, you need a new variable, which gets switched every time the mouse button is clicked. Something like this:

var PlayAim = false;

function Update() {
    if (Input.GetButtonDown("Aim") {
        if (PlayAim == false) {
            PlayAim = true;
        else { // else PlayAim is true
            PlayAim = false;

Note that the PlayAim variable is declared outside the function (This is Javascript, I presumed that's what you were using). Also be careful about using double-equals '==' versus single-equals sign '='.

Stop the aim animation (do something like `animation.Stop("aim");`), if the other animations are still running, they should show up again.

Thank you, but the problem still persists, sorry Im very new to programming, this is what I try to do under function Update:

if(Input.GetButtonDown("Aim")) { animation.Play("aim"); } else { animation.Stop("aim"); //animation["aim_pistol"].enabled = false; }

It sometimes switches very fast and I want the animation to play once key is pressed, and I want it to stop playing once its pressed again.

Thank you for your answers.

Thank you, I went on a similar path before but missed the double = . Its working fine now, thanks again :).