Hi I have a code for my player to move if you push two buttons. If both statements are true (both buttons are pushed). then the player should move. However it doesn’t. the weird thing is that it does when it’s outside the IF-statement.
// Update is called once per frame
void FixedUpdate () {
// the player does move when this is uncommented:
//transform.Translate(0f, -1f * Time.deltaTime, 0f);
if (Button1down == 1&& Button2down == 1)
{
//player must move
transform.Translate(0f, -1f * Time.deltaTime, 0f);
}
}
is button1down a boolean? if yes then it should be if(button1down == true && button2down == true)
{…
}
or short if(button1down&&button2down)
{… }
void FixedUpdate () {
// the player does move when this is uncommented:
//transform.Translate(0f, -1f * Time.deltaTime, 0f);
if (Button1down == 1 && Button2down == 1)
{
//player must move
transform.Translate(0f, -1f * Time.deltaTime, 0f);
}
}
maybe try adding a space b/w the button1down == 1 && instead of 1&& maybe that is causing problem
Make sure Button1down & Button2down aren’t == 1 for one frame only, the log inside the if may be misleading as it will trigger once, and so will the Translate, but given you’re using Time.deltaTime, for the duration of one frame (e.g 0.001 something) the Translate won’t be nitceable. Check the transform in the editor while running play mode, it’s highly likely that your if state is only valid once.