Question by
CaptainCapsize · Jan 27, 2018 at 01:08 PM ·
c#scripting problemcoroutinewaitforseconds
StartCoroutine not listening to parameters
Hello, I'm using the following code, but once I hit play it immediatly runs as if dead = true (It disables the rigidbody, but doesn't reanable it and restart, it's just stuck at "You died" displayed). I couldn't find an answer anywhere else so I decided to open a new question.
public class PlayerController : MonoBehaviour {
public bool dead = false; void Start ()
{
deathText.text = "";
StartCoroutine (Death());
}
IEnumerator Death()
{
if (dead = true)
{
BeforeDeath ();
yield return new WaitForSeconds (2.0f);
AfterDeath ();
}
}
Comment
Best Answer
Answer by UnityCoach · Jan 27, 2018 at 01:17 PM
You mean to do if (dead == true)
in place of if (dead = true)
Otherwise you assign the value true
to dead
, you need to use ==
to make a comparison.