- Home /
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.
Answer by eddyvanleuten · Jun 13, 2013 at 06:44 AM
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;
}
}
Your answer
Follow this Question
Related Questions
Need help with If/else statement. 1 Answer
Problem with IF with 2 outputs. 1 Answer
If/Else Statement resulting in glitched animation. 1 Answer
if,if,if, string cases, and if not, then something else? 1 Answer
Problem with On/Off Switch 1 Answer