Button if else statement?

Hey Unity Answers community,

If I was to make an else statement for a singular button, were if you hit the non-desired key it would go back 2 points on the axis rather than +2 on the axis, how would I go about doing that?

And also, how can I make it so the desired button can only be hitten once? rather than be spammed.

Here’s the code for one of my buttons:

function Update () {

if(buttons[0])
     {
     if(Input.GetKeyDown("q"))
{ 
other.transform.Translate(Vector3(0.5,0,0));                  
}
     } 

Thanks in advace.

With this code your gameobject should move only once ( and dont forget the Time.delta! ):

    function Update()
        {
        	if(Input.GetKeyDown("q") && keyPressed == false)
        	{
        		transform.translate(Vector3(-2f,0,0)*Time.delta)
        		keyPressed = true;
        	}
        }