I have a coroutine with a while loop that I’d like to keep repeating for a couple seconds until a condition is met but it isn’t looping through multiple times so I cant make a gun look at another object using slerp. What is causing the while loop to be run one time then shut off? What is the best way to make a while loop run until a condition is met? Would a bool be the best way or no? The code below is suppose to run for a couple seconds then by the time the waitforseconds is done the gun should be done moving. Is this the best way to do this? Thanks for the info
public IEnumerator LookAt1()
{
LookAt = true;
while (LookAt == true) {
//Body
Quaternion Rot1 = Quaternion.LookRotation (RM.Priority1Plastic [0].transform.FindChild ("LookAt1").position - this.gameObject.transform.position);
this.gameObject.transform.rotation = Quaternion.Slerp (this.gameObject.transform.rotation, Rot1, Time.deltaTime * 3);
//Gun
Quaternion Rot = Quaternion.LookRotation (RM.Priority1Plastic [0].transform.FindChild ("LookAt1").position - Gun.transform.position);
Gun.transform.rotation = Quaternion.Slerp (Gun.transform.rotation, Rot, Time.deltaTime * 3);
}
yield return new WaitForSeconds (3);
LookAt = false;
}