This is what I could come up with off the top of my head (needs testing)…
void FixedUpdate()
{
bool buttonActive = false;
if(Input.GetKey (KeyCode.UpArrow))
{
buttonActive = true;
//Add Force
}
//Not using else because both up and down can be true during the frame
if(Input.GetKey (KeyCode.DownArrow))
{
buttonActive = true;
//Add Force
}
//If neither button is being pressed buttonActive will remain false
if(!buttonActive)
{
rigidBody.velocity = new Vector3(0,0,0); //Stop object
}
}
There is probable a better way to do it, but hope it helps
Extra: When adding force in FixedUpdate you don’t need Time.deltaTime as it runs at a fixed rate. You need to use Time.deltaTime in Update when adding force, or your forces will be different across different size devices.
Also Input should be in Update, so you may want to switch from FixedUpdate to Update and use Time.deltaTime on your forces.
I was just having trouble on the else part, what do I put when I want to check for non-input “when the player is not pressing a button”. Else didn’t seem to work so I guess I could use a boolean. Lets see how that works @Raimi