- Home /
Question by
nmehta6404 · Feb 27, 2019 at 09:53 PM ·
inputgetkeydowngetkey
how can i use getkey and getkeydown for two diffrent functions.
for example we say in pubg when we hold the right mouse button then camera lerps forward and when we simple press the mouse button once we can use scope.
so how can i use the Input.GetKey(Keycode.Space) for function1();
Input.GetKeyDown(Keycode.Space) for function2();
Comment
Answer by WarmedxMints · Feb 27, 2019 at 10:03 PM
What you could do is use the key up event and a timer.
private float _pressTime;
[SerializeField]
private float _pressTollence = 0.2f;
private void Update()
{
if (Input.GetKey(KeyCode.Space))
{
_pressTime += Time.deltaTime;
if (_pressTime > _pressTollence)
{
Debug.Log("Space Held");
}
}
else if (Input.GetKeyUp(KeyCode.Space) && _pressTime <= _pressTollence)
{
Debug.Log("Space Pressed");
}
else
{
_pressTime = 0;
}
}
Answer by nmehta6404 · Feb 27, 2019 at 11:07 PM
That was very help full thank you so much @WarmedxMints.
Your welcome. If it worked you mark your question as answered or solved, please.