# Alternaing input

**URL:** https://discussions.unity.com/t/alternaing-input/29261
**Category:** Questions & Answers
**Created:** [September 30, 2011, 12:18pm UTC](https://discussions.unity.com/t/alternaing-input/29261 "2011-09-30T12:18:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [September 30, 2011, 12:18pm UTC](https://discussions.unity.com/t/alternaing-input/29261/1 "2011-09-30T12:18:59Z")

</div>

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");
      	}
}

```

---

<div class="post-metadata">

### Author: ![GradesFisher](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@GradesFisher](https://discussions.unity.com/u/GradesFisher)
#### Post date: [September 30, 2011, 12:36pm UTC](https://discussions.unity.com/t/alternaing-input/29261/2 "2011-09-30T12:36:23Z")

</div>

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...):

```auto
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
