Very fast User Input Game in Unity

I played the game Ready-Steady-Bang recently and tried myself just to write a basic code and give it a try.So I used coroutines and Debug.log to play the game in editor.However as I decrease the time it takes for enemy to shoot. The problem is I lose immediately.Is it because I am playing with a keyboard vs touch on mobile phones or something else?Also sometimes it happens even though Bang has printed It takes quite a large time for me to press Q and win?What is that I am doing wrong?Here is the code-

 public class Bang : MonoBehaviour 
    {
    	void Start () 
    	{
    		StartCoroutine(Game(0.2f));//provide the enemy speed!
    	}
    
    
    	IEnumerator common()
    	{
    
    		yield return new WaitForSeconds(2.0f);
    		Debug.Log("Lets start again");
    		yield return new WaitForSeconds(1.0f);
    
    	}
    	IEnumerator Game(float opponentTime)
    	{
    		float timer;
    		float waitForBang;
    		bool winner;
    	
    		bool breaked;
    		while(true)
    		{
    
    
    			waitForBang = Random.Range(1.0F,4.0F);
    			winner = false;
    			timer = 0;
    			Debug.Log("Ready");
    			breaked = false;
    			if(!Input.anyKey)//stop player
    			{	
    				Debug.Log("Steady");
    				while((timer<=waitForBang))
    				{
    					if(Input.anyKey)
    					{	breaked = true;
    						break;
    					}
    					timer+=Time.deltaTime;
    					yield return null;
    				}
    				timer = 0;
    				if(!breaked)
    				{
    					Debug.Log("BANG");
    					while(timer<=opponentTime)//here is the time to shoot for the player
    					{
    						if(Input.GetKey(KeyCode.Q))
    						{
    							winner = true;
    							break;
    						}
    						timer+=Time.deltaTime;
    						yield return null;
    					}
    					if(winner)
    					{
    						Debug.Log("you win");
    
    						//Enemy killed and your win animation here
    					}
    					else
    					{
    						Debug.Log("you lose");
    
    						//You killed and enemy win animation
    					}
    					yield return StartCoroutine(common());
    				}
    				else
    				{
    					Debug.Log("you lose");
    					yield return StartCoroutine(common());
    				}
    			}
    			else
    			{
    				Debug.Log("you lose");
    				yield return StartCoroutine(common());
    
    			
    			}
    		}
    
    
    
    
    	}
    
    
    
    
    
    
    
    
    
    
    
    
    
    }

The issue is probably because the time it takes for him to shoot you is 0.2 seconds!

Have you tried making any reflex tests or something? It’s really really hard to react in that amount of time, I usually get like 300ms (if the trigger is on release, if I click the mouse and release just as I see something changing I can barely get under 200ms).

Keep in mind that your brain also lags, when you say “BS! I pressed jump just before I fell into the hole!” No you didn’t, your brain just reacted slower than you thought.

What I recommend is to add a Debug.Log(Timer) after you’ve started it, and to be sure you could add one for the opponentTime as well.

Also, add another one that tells you how long it took you to actually press the button.

You’re losing instantly because 0.2 seconds IS practicaly “instant” to your brain :stuck_out_tongue:

The Debug.Log things I told you to do won’t fix anything, but they will show you if those components are working as they should, if they are then it really is a problem that you’re just making it too fast :wink: