leegod
June 22, 2020, 5:06am
1
For console UI, when select something from many elements from some list,
if user press Keyboard up, down arrow or console pad’s d-pad key and maintaining it,
at first UI select above element from current cursor positioned element,
and if user keep pressing button, UI start navigate fastly to direction user’s input.
How to implement this?
I tried
if (Input.GetKey(KeyCode.UpArrow))
{
CallSome();
}
but was too fast at first, so can’t select properly.
So should call startcoroutine and using waitforseconds rather than call just function?
private readonly float delayBetweenInputs = 1f;
private float t;
private void Update()
{
if (Input.GetKey(KeyCode.UpArrow) && t >= 0)
{
// Your action here
t = delayBetweenInputs;
}
t -= Time.deltaTime;
}
Just wait for X seconds between each registered call. Basically, a simpler version of a coroutine.
Dextozz:
private readonly float delayBetweenInputs = 1f;
private float t;
private void Update()
{
if (Input.GetKey(KeyCode.UpArrow) && t >= 0)
{
// Your action here
t = delayBetweenInputs;
}
t -= Time.deltaTime;
}
Just wait for X seconds between each registered call. Basically, a simpler version of a coroutine.
bro if you say t >= 0 he never go in the action because t -= Time.deltaTime always go under 0.
1 Like
t = delayBetweenInputs;
It still should be t <= 0 tho
1 Like
Input gives you a multiplier (a real number in the range from -1.0 to 1.0) that is used for later actions. The longer you hold the button the closer you are to border values (like in arcade games, one step, slow run, sprint). You can just simply translate this value to what you want (or write a mathematical formula) and don’t have to lock the key for some time.
Ryiah
May 31, 2023, 4:16pm
6
GetKey (and GetButton) doesn’t.