Alternaing input

Right now i have it set up in my game that when you hit the “Z” button it plays a certain animation that brings red cubes forward and when you hit “X” the blue ones go back and the red ones come forth. What i want is to some how just have to hit one button and each time it will alternate between loading the first or second animation.

As you can see i have to hit different button. but i want it so that say every second hit
of the Z key will play the second animation. Hope you guys know what i mean. Anyways here’s
what im using now.

function Update () {
    if (Input.GetButtonDown ("Fire1"))    
     {
     	
   animation.Play("Retryback");
   
      }
      
      if (Input.GetButtonDown("Fire2"))
      {
      	animation.Play("Retryforward");
      	}
}

1 Answer

1

All you would have to do is create a variable that holds the current position so that each time you click the button, it knows whether to bring it forward or back.

It sounds a bit confusing, but look at this script (Assuming you want to use the left mouse button as the button that performs the animations...):

var Retry = "forward";

function Update () {
    if(Input.GetButtonDown("Fire1"))    
    {
        if(Retry == "forward"){
            animation.Play("Retryback");
            Retry = "back";
          }
        else
        {
        animation.Play("Retryforward");
        Retry = "forward";
        }
    }
}

Hopefully this should work for what you want!!!!

If you need more help, feel free to comment back!

-Grady

you're welcome, glad I could help!!! -Grady

–