- Home /
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());
}
}
}
}
Answer by Madcowe · Oct 27, 2014 at 06:19 PM
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 :P
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 ;)
have you played the game on phone?I myself have got time under 0.2 seconds and then only it gets exciting to play.If 0.2 seconds IS practicaly "instant" to my brain then how do i am able to do it in the game
Try the tests I told you about, use the Debug.Log and then tell me the values.
A question though, are you testing on the phone or the pc?
I am testing on pc probably the time it takes to press key is more than touch response on phone.I debug.log the enemy time and indeed it was just >=0.2 secs so that is working correct.I may test it on phone in the future.
yea as I mentioned, while on the mobile things work "on click" in the PC they usually work "on release", so what I'm pretty sure happens is you get the call to press the button, but you spend time clicking and then releasing, and that's why you can't do it.
If you know if have a reaction time faster than 0.2s try this: Hold down the button, and when the warning appears release it (ins$$anonymous$$d of pressing) and see if that works :P
If it does you just have to change the code so it recognizes input "on$$anonymous$$eyDown" ins$$anonymous$$d of "on$$anonymous$$eyUp" or something like that ;)
Your answer
Follow this Question
Related Questions
Input management with coroutines in a fighting game. 0 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Checking Input on 2 different coroutines at the same time 1 Answer
So I'm trying to make a combo with multiple attacks per layer, and not sure how. 0 Answers
Help with waiting for input? I'm too used to how Console.ReadLine() works. 0 Answers