c# – Is it ok to read inputs like this in Unity?
Suddenly I got the idea that GetKeyDown input can also be read in fixedupdate, especially since I already use the jumpContinuing variable.
This way you can avoid Update (if you need to). But there must be a catch.
I’m not saying it’s better, I’m just wondering if it’s normal to do it this way.
Here is the code in FixedUpdate
if (!jumpContinuing && grounded && Input.GetKey(KeyCode.Space))
{
jumpContinuing = true;
}
if (jumpContinuing)
{
if (!Input.GetKey(KeyCode.Space))
{
jumpContinuing = false;
}
}
And in Update
if (grounded && Input.GetKeyDown(KeyCode.Space))
{
jumpContinuing = true;
}
if(Input.GetKeyUp(KeyCode.Space))
{
jumpContinuing = false;
}
Read more here: Source link