Question by
dmoran55555 · Aug 31, 2021 at 03:38 AM ·
inputvariabletime
How do I make a script that waits for player input or no player and then does something according to that?
Right now, I have a script for bhopping. I want it to work so that after the player jumps, they have a 0.2 second window when they land to jump again and game some speed. Currently, when I use this, it crashes unity.
bool bhop = false;
public float bhopwindow = 0.2f;
float startTime = Time.time;
if(Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
bhop = true;
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
while (bhop && isGrounded)
{
if (Input.GetKeyDown(KeyCode.Space))
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
bhop = true;
speed += 0.5f;
}
else if(Time.time - startTime >= bhopwindow)
{
bhop = false;
speed = normalspeed;
}
}
}
Comment