- Home /
This question was
closed May 25, 2019 at 12:02 AM by
DoctorChar for the following reason:
Problem is not reproducible or outdated
Question by
DoctorChar · May 24, 2019 at 11:58 AM ·
yieldienumeratorif statement
wait until something while checking for something else
private IEnumerator WaitForShield(float waitTime)
{
print("hi1");
shield.SetActive(true);
if (Input.GetKey(KeyCode.I))
{
if (Input.GetKey(KeyCode.S) && NotShielding == false)
{
anim.SetInteger("AnimParameter", 8);
shield.SetActive(false);
yield return new WaitForSeconds(0.667f);
anim.SetInteger("AnimParameter", 7);
}
}
yield return new WaitUntil(() => (!Input.GetKey(KeyCode.I)));
shield.SetActive(true);
print("hi2");
anim.SetInteger("AnimParameter", 7);
print(anim.GetInteger("AnimParameter"));
yield return new WaitForSeconds(waitTime);
print("hi3");
shield.SetActive(false);
NotShielding = true;
}
I need the if (Input.GetKey(KeyCode.I)) to run while the yield return new WaitUntil(() =>(!Input.GetKey(KeyCode.I))); happens Using a while loop where the if is crashes Unity
Comment
Answer by dontdiedevelop · May 24, 2019 at 12:58 PM
Delete the yield return new WaitUntil(() => (!Input.GetKey(KeyCode.I)));
And write
while(!Input.GetKey(KeyCode.I)) { yield return null; }
Follow this Question
Related Questions
Wait For Seconds c# 3 Answers
Only the first half of my coroutine works 1 Answer
IEnumerator solution! 1 Answer