using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class YieldTest : MonoBehaviour {
public bool b = true;
public IEnumerator myIEnumertor = null;
void Awake()
{
}
// Use this for initialization
void Start ()
{
myIEnumertor = GenerateFibonacci().GetEnumerator();
int i = 0;
do
{
myIEnumertor.MoveNext();
Debug.Log(myIEnumertor.Current);
i++;
}
while (i < 10);
}
// Update is called once per frame
void Update ()
{
}
public static IEnumerable<int> GenerateFibonacci()
{
yield return 0;
yield return 1;
int last0 = 0, last1 = 1, current;
while (true)
{
current = last0 + last1;
yield return current;
last0 = last1;
last1 = current;
}
}
}