I’m trying to make a Super Jump in my platformer game. Depending on how long you press a key, the character should jump higher or lower.
private int timer = 3;
public float JumpForcePS;
private float PowerJump = 0;
private void Update()
{
if (Input.GetKey(KeyCode.LeftShift) && IsGrounded)
{
if (timer > 0)
{
PowerJump += JumpForcePS;
timer--;
//Somehow make it wait 1 second before executing code again
}
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
rb.velocity = Vector2.up * PowerJump;
timer = 3;
PowerJump = 0;
}
}
In my case PowerForcePS is 7. The problem here is that when pressing Left Shift PowerJump will always equal 21. I want so that if you press for 1 second it will equal 7, if it’s pressed for 2 seconds it will equal 14 and if it’s pressed for 3 seconds it will be 21. How do I execute the code in “if (Timer > 0)” every second instead of every frame?