Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Last active October 10, 2021 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unity3dcollege/198f67001f0d78f02aa40d9b8bada7b7 to your computer and use it in GitHub Desktop.
Save unity3dcollege/198f67001f0d78f02aa40d9b8bada7b7 to your computer and use it in GitHub Desktop.
InputExample.cs
//Using the new Unity input system,
// a simple code that takes the player animation from a walk to a run if the _axisInput.x is held for 2 seconds.
// Something like this non working code where speed > 3 is run and less than 3 is walk and 2f is time the input key is held down:
// YES, we are very new at this lol
if (_axisInput.x >= Time.deltaTime * 2f)
_animator.SetFloat("Speed", 3);
else
else _animator.SetFloat("Speed", -.02f);
// answer
float heldTime = 0f;
void Update()
{
if (_axisInput.x > 0)
{
heldTime += Time.deltaTime;
if (heldTime > 2f)
{
// speed boost
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment