I want my player to jump once then land, but if I press the jump button again, the player will still jump in midair(while falling). Its a 2d, c# game.
void Start () {
}
void Update () {
if (Input.GetKeyDown ("space")){
transform.Translate(Vector3.up * 260 * Time.deltaTime, Space.World);}
}
A simple boolean will help control it:
// at the top with your class members
bool isJumping = false;
// then in your update function
Void Update()
{
if (Input.GetKeyDown("space") && !isJumping)
{
isJumping = true;
transform.Translate(Vector3.up * 260 * Time.deltaTime, Space.World);
}
}
Then you just set isJumping back to false somewhere (not in update as I believe it runs many many times per second).
Beware this is untested as I am at work. Hope this helps.