unity how to call function when key is held down and stop when key is not held down code example
Example 1: how to see if they are aholding down a key unity
input.GetKey("Key")
Example 2: How to hold key down unity
Input.GetKey("Key")
if (Input.GetKey("Key"))
{
}
if (Input.GetKey("left shift"))
{
RunBool = true;
WalkBool = false;
}
Example 3: how to check if key is held in unity
float startTime;
void Update () {
if (Input.Get$$anonymous$$eyDown("w")||Input.Get$$anonymous$$eyDown("s")){
startTime = Time.time;
}
if (Input.Get$$anonymous$$eyUp("w")||Input.Get$$anonymous$$eyDown("s")){
float timePressed = Time.time - startTime;
}
RandNum = Random.Range(1, 1000);
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W) || Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.S)){
if(RandNum > 1){
if(RandNum < 1000){
inBattle ();
}
}
}
}