Hello, I have a float “Levelint” and I want to increase it by one while I am holding the right arrow. So, when I hold the right arrow it will increase by one, every second, and if I just press the right arrow, to just add one, once.
Does anyone know how to do this? Any help would be appreciated, thanks!
If the question doesn’t make sense, let me know and I can try to explain it better.
private float Levelint;
private int lastTimeInt = -1;
If (Input.GetKey(KeyCode.ArrowRight)) // i am not sure if it is ArrowRight
If ((int)Time.time > lastTimeInt) Levelint++;
lastTimeInt = (int)Time.time;
else If (Input.GetKey(KeyCode.ArrowRight)) // i am not sure if it is ArrowRight
LastTimeInt = -1;
public int Levelint;
private float timer;
I will give you psuedo code,
- Based on Key press, set isPressed bool value to true;
- in update, if isPressed is true, increase a timer counter += Deltatime,
- If counter > 1 , change level / do what you want to do, reset counter to 0.
- If isPressed becomes false, change counter to 0.