Update {
while(active) {
switch (state) {
case 0:
//0
break;
case 1:
//1
break;
case 2:
//2
break;
case 3:
//3
break;
case 4:
//4
break;
}
if (Input.GetButtonDown ("Fire1") && state < 4) {
Debug.Log ("test");
mouseWheel = 1.0f;
++state;
} else {
mouseWheel += Input.GetAxis ("Mouse ScrollWheel");
if (mouseWheel < 1) mouseWheel = 1.0f;
}
}
}
How could I get the same output in a co-routine? I have tried so many times but I just can’t figure it out.
This is how i’d do it…
IEnumerator MyCoRoutine() {
while(active) {
switch (state) {
case 0:
//0
break;
case 1:
//1
break;
case 2:
//2
break;
case 3:
//3
break;
case 4:
//4
break;
}
if (Input.GetButtonDown ("Fire1") && state < 4) {
Debug.Log ("test");
mouseWheel = 1.0f;
++state;
} else {
mouseWheel += Input.GetAxis ("Mouse ScrollWheel");
if (mouseWheel < 1) mouseWheel = 1.0f;
}
yield return 0; //Wait for Next Update
//Or yield return WaitForFixedUpdate();
//Or yield return new WaitFOrSeconds(0.5f)
}
yield break; //Not Active.. Finish with this co-routine
}
And start the coroutine… from wherever… like this…
StartCoroutine(“MyCoRoutine”);
And if you want to “kill” it prematurely, use StopCoroutine(“MyCoRoutine”);