Question by
BlobOfAwe · Aug 17, 2020 at 06:47 PM ·
inputif-statementsloopingdebug.logwhile-loop
If Statement within a while loop only checks the if condition once.
I have this code that is trying to say; "While this is true, check for player input". The issue is that it only detects player input on the first run of the While loop, after that it will only ever treat the If condition as false.
Here is the code;
IEnumerator SlowDown()
{
while (Input.GetButton("Slow") && canThrow && isControllable)
{
Debug.Log("Ran While-Loop");
if (Input.GetButtonDown("Jump") && !needleController.thrown && !needleController.collided)
{
Debug.Log("Found Input");
needle.transform.position = transform.position;
needle.SetActive(true);
needleController.thrown = true;
}
else { Debug.Log("Found no input"); }
timeManager.Slowdown();
yield return new WaitForEndOfFrame();
}
timeManager.setToRealtime = true;
aimGroup.SetActive(false);
}
And here is the Debug.Log result if I offer player input on the first frame. This doesn't change regardless of whether I offer input afterwards.
capture.png
(17.3 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613005853im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Linking Trigger to Input (or directly into Character Control script) 0 Answers
Fishing mini game automatically restarting and not working as intended 1 Answer
combination lock with a feedback 0 Answers
why infinit loop ? what im doing wrong? 3 Answers
While loop crashing in update but why not if statement? 2 Answers