New answers tagged

6

To answer your first Question "why does the Engine behave like this" I would add the following: The Engine does not actually detect the key being pressed multiple times. What you need to keep in mind here is that the "was pressed" state of the key does not reset until the next frame, and your code will be executed in a single frame. Furthermore, every if ...


5

It is due to your flow is confusing for engine as it will try to execute your every check in every frame. Try to implement with else or with single statement like, using UnityEngine; using System.Collections; public class TestingKeyGetRecursion : MonoBehaviour { int counter = 1; void Update () { if (Input.GetKeyDown(KeyCode.F)) ...


2

Try adding an "else-if" instead of a normal "if". So your update method should look like this: void Update () { if(counter == 1 && Input.GetKeyDown("f")) { counter = 2; Debug.Log(counter); } else if(counter == 2 && Input.GetKeyDown("f")) { counter = 3; Debug.Log(counter); } else ...



Top 50 recent answers are included