Reputation: 15
I am trying to make it so that when my character jumps the jump key is disabled until his jumpHeight == 0 (he is back on the floor). Is there an easy function in C# to be able to do this? For example:
if (jumpHeight > 0)
{
keys.space == disabled
}
Thanks in advance.
Upvotes: 0
Views: 224
Reputation:
Your approach means more pointless work, and won't allow you to disable the actual input anyway. Instead, you should choose to not perform any checks on the status of particular keys if a condition is met.
public void Update(GameTime gt)
{
if (canCheckSpace)
{
if (spaceIsPressed())
{
doThings();
}
}
if (jumpHeight > 0)
{
canCheckSpace = false;
}
}
If you wish to "disable" a key for all of the scripts checking for it, consider wrapping the input into your own manager, that will check for those conditions and act accordingly, for any script calling its public methods.
Upvotes: 5