yield with while via C#

Hey guys, I hope everyone is working on something cool.

I am trying to write the following code in C# but cant figure out the syntax, if you know the syntax or better yet point me to a resource where I can look this type of stuff up in the future without bothering everyone, that would be great thanx.

This is a Javascript version of what I want to create in C#

private var dead : boolean = false;

function Start(){
  while(true){
    while(!dead) yield;
    Debug.Log("dead");
    dead = false;
  }
}

And this is what I have in C# but as you can see, I am writing the yield part wrong.

bool dead = false;
void Start(){
  StartCoroutine(Run());
}
IEnumerator Run() {
  while(true){
    while(!dead) yield;????
    Debug.Log("dead");
    dead = false;
}
}

Thanx guys.

For the code given, you probably mean to write:

yield return null;

otherwise, the Scripting Reference has example in all three languages for most docs.

private bool dead = false;

IEnumerator Start(){
  while(true){
    while(!dead) yield return null;
    Debug.Log("dead");
    dead = false;
  }
}

Well first off, you’re certainly not bothering anyone here. In fact, for my case, you’re helping me become a better programmer by troubleshooting other people’s code. It’s actually a great learning exercise.

Let me help you with a great resource, Unity - Scripting API:. This is the API of Unity.

Now, back to your question, the yield is wrong. I don’t think you know exactly what the Yield is supposed to be doing (I say that but I could be wrong).

Just doing a quick search on the API I found this link: http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html

It’s all about Coroutines and the yield you’re using.

When I think of yield, I think of the command WaitForSeconds(). But from the looks of it, it does do other functions.

What would you like your code to be doing, and then perhaps I can help further.