using UnityEngine;
using System.Collections;
/// <summary>
///测试 public void StopCoroutine(IEnumerator routine);
/// </summary>
public class TestHHH : MonoBehaviour
{
IEnumerator helloIenumeratro;
void Start()
{
//必须是——StopCoroutine(IEnumerator routine)方式
helloIenumeratro = testStartCor("今天的天气哈哈哈");
StartCoroutine(helloIenumeratro);
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//对应——StopCoroutine(IEnumerator routine)方式
StopCoroutine(helloIenumeratro);
Debug.Log("已经停止协程");
}
}
IEnumerator testStartCor(string ss)
{
var cout = 0;
while (true)
{
yield return new WaitForSeconds(1);
cout++;
Debug.Log("StartCoroutine:" + cout+" "+ss);
}
}
}
原文https://blog.csdn.net/aiyan1111111/article/details/54236301
网友评论