using UnityEngine;
using System.Collections;
public class CorountineTest01 : MonoBehaviour {
// Use this for initialization
void Start () {
// //Debug.Log("Test Start");
yield return StartCoroutine(Test());
// StartCoroutine(Test02(3));
// //Debug.Log("Test End");
//延迟3秒之后 执行方法Test03
Invoke("Test03",3);
InvokeRepeating("Test03", 0, 2);
}
// Update is called once per frame
void Update () {
}
IEnumerator Test02(int wave)
{
int count = 0;
while (count<wave)
{
count++;
yield return StartCoroutine(Test01(5));
if (count==1)
{
StopAllCoroutines();//break
}
Debug.Log("第" + count + "波怪产生结束");
yield return new WaitForSeconds(5);
Debug.Log("注意,下一波即将产生");
}
Debug.Log("游戏结束");
}
void Test03()
{
Debug.Log("InvokeTest");
}
IEnumerator Test01(int number)
{
//yield return new WaitForSeconds(2);
//Debug.Log("终于执行到了***");
//yield return new WaitForSeconds(3);
//Debug.Log("执行3秒");
//yield return new WaitForSeconds(4);
//Debug.Log("执行4秒");
//yield return new WaitForSeconds(5);
//Debug.Log("执行5秒");
int count = 0;
while (count<number)
{
count++;
yield return new WaitForSeconds(1);
Debug.Log("这是产生的第" + count + "个怪物");
}
}
}
using System.Collections;
public class CorountineTest01 : MonoBehaviour {
// Use this for initialization
void Start () {
// //Debug.Log("Test Start");
yield return StartCoroutine(Test());
// StartCoroutine(Test02(3));
// //Debug.Log("Test End");
//延迟3秒之后 执行方法Test03
Invoke("Test03",3);
InvokeRepeating("Test03", 0, 2);
}
// Update is called once per frame
void Update () {
}
IEnumerator Test02(int wave)
{
int count = 0;
while (count<wave)
{
count++;
yield return StartCoroutine(Test01(5));
if (count==1)
{
StopAllCoroutines();//break
}
Debug.Log("第" + count + "波怪产生结束");
yield return new WaitForSeconds(5);
Debug.Log("注意,下一波即将产生");
}
Debug.Log("游戏结束");
}
void Test03()
{
Debug.Log("InvokeTest");
}
IEnumerator Test01(int number)
{
//yield return new WaitForSeconds(2);
//Debug.Log("终于执行到了***");
//yield return new WaitForSeconds(3);
//Debug.Log("执行3秒");
//yield return new WaitForSeconds(4);
//Debug.Log("执行4秒");
//yield return new WaitForSeconds(5);
//Debug.Log("执行5秒");
int count = 0;
while (count<number)
{
count++;
yield return new WaitForSeconds(1);
Debug.Log("这是产生的第" + count + "个怪物");
}
}
}