using UnityEngine;
using System.Collections;
public class WaitForSecondsExample : MonoBehaviour {
void Start() {
StartCoroutine(Example());
}
IEnumerator Example() {
print(Time.time);
yield return new WaitForSeconds(5);
print(Time.time);
}
}
I don't like using functions in my code. Instead of the example above, I'd prefer:
using UnityEngine;
using System.Collections;
public class WaitForSecondsExample : MonoBehaviour {
void Start() {
yield return new WaitForSeconds(5);
print(Time.time);
}
I can easily use yield In javascript but why can't I use yield in c# without using a function?
// Prints 0
print (Time.time);
// Waits 5 seconds
yield WaitForSeconds (5);
// Prints 5.0
print (Time.time);
I have many problem with using functions in C#.