StartCoroutine/StopCoroutineInvoke
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_Coroutine.html
using UnityEngine;
using System.Collections; public class CoroutineTest : MonoBehaviour { void Start () {
print("Starting " + Time.time);
StartCoroutine(WaitAndPrint(0.2F));
print("Before WaitAndPrint Finishes " + Time.time);
} IEnumerator WaitAndPrint(float waitTime) {
print("StartCoroutine1 " + Time.time);
StartCoroutine("DoSomething", 2.0f);
print("StartCoroutine2 " + Time.time);
yield return new WaitForSeconds(waitTime);
print("StopCoroutine1 " + Time.time);
StopCoroutine("DoSomething");
print("StopCoroutine2 " + Time.time);
} IEnumerator DoSomething(float someParameter) {
while (true) {
print("DoSomething Loop");
yield return null;
}
} void Projectile() {
print("Projectile " + Time.time);
} void LaunchProjectile() {
print("LaunchProjectile " + Time.time);
} // Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Space) && !IsInvoking("LaunchProjectile")) {
InvokeRepeating("LaunchProjectile", 2f, 0.5f);
Invoke("Projectile", 2f);
}
if (Input.GetKeyDown(KeyCode.X)) {
Debug.Log("CancelInvoke");
CancelInvoke("LaunchProjectile");
}
}
}
#region Assembly UnityEngine.dll, v0.0.0.0
// D:\Program\Unity Project\test\Library\UnityAssemblies\UnityEngine.dll
#endregion using System;
using System.Collections;
using UnityEngine.Internal;
using UnityEngine.Scripting; namespace UnityEngine {
// Summary:
// MonoBehaviour is the base class every script derives from.
[RequiredByNativeCode]
public class MonoBehaviour : Behaviour {
[WrapperlessIcall]
public MonoBehaviour(); // Summary:
// Disabling this lets you skip the GUI layout phase.
public bool useGUILayout { get; set; } // Summary:
// Cancels all Invoke calls on this MonoBehaviour.
public void CancelInvoke();
//
// Summary:
// Cancels all Invoke calls with name methodName on this behaviour.
//
// Parameters:
// methodName:
[WrapperlessIcall]
public void CancelInvoke(string methodName);
//
// Summary:
// Invokes the method methodName in time seconds.
//
// Parameters:
// methodName:
//
// time:
[WrapperlessIcall]
public void Invoke(string methodName, float time);
//
// Summary:
// Invokes the method methodName in time seconds, then repeatedly every repeatRate
// seconds.
//
// Parameters:
// methodName:
//
// time:
//
// repeatRate:
[WrapperlessIcall]
public void InvokeRepeating(string methodName, float time, float repeatRate);
//
// Summary:
// Is any invoke pending on this MonoBehaviour?
public bool IsInvoking();
//
// Summary:
// Is any invoke on methodName pending?
//
// Parameters:
// methodName:
[WrapperlessIcall]
public bool IsInvoking(string methodName);
//
// Summary:
// Logs message to the Unity Console (identical to Debug.Log).
//
// Parameters:
// message:
public static void print(object message);
//
// Summary:
// Starts a coroutine.
//
// Parameters:
// routine:
public Coroutine StartCoroutine(IEnumerator routine);
//
// Summary:
// Starts a coroutine named methodName.
//
// Parameters:
// methodName:
//
// value:
[ExcludeFromDocs]
public Coroutine StartCoroutine(string methodName);
//
// Summary:
// Starts a coroutine named methodName.
//
// Parameters:
// methodName:
//
// value:
[WrapperlessIcall]
public Coroutine StartCoroutine(string methodName, object value);
[WrapperlessIcall]
public Coroutine StartCoroutine_Auto(IEnumerator routine);
//
// Summary:
// Stops all coroutines running on this behaviour.
[WrapperlessIcall]
public void StopAllCoroutines();
public void StopCoroutine(Coroutine routine);
//
// Summary:
// Stops the first coroutine named methodName, or the coroutine stored in routine
// running on this behaviour.
//
// Parameters:
// methodName:
// Name of coroutine.
//
// routine:
// Name of the function in code.
public void StopCoroutine(IEnumerator routine);
//
// Summary:
// Stops the first coroutine named methodName, or the coroutine stored in routine
// running on this behaviour.
//
// Parameters:
// methodName:
// Name of coroutine.
//
// routine:
// Name of the function in code.
[WrapperlessIcall]
public void StopCoroutine(string methodName);
}
}
- yield; The coroutine will continue after all Update functions have been called on the next frame.
yield:协程在所有的Update函数于下一帧调用后继续执行。 - yield WaitForSeconds(2); Continue after a specified time delay, after all Update functions have been called for the frame
yield WaitForSeconds(2):在一个指定的时间延迟后继续执行,在所有的Update函数被调用之后。 - yield WaitForFixedUpdate(); Continue after all FixedUpdate has been called on all scripts
yield WaitForFixedUpdate():在所有脚本上所有的FixedUpdate被调用之后继续执行。 - yield WWW Continue after a WWW download has completed.
yield WWW:在WWW加载完成之后继续执行。 - yield StartCoroutine(MyFunc); Chains the coroutine, and will wait for the MyFunc coroutine to complete first.
yield StartCoroutine(MyFunc):用于链接协程,此将等待MyFunc协程完成先
yield WaitForEndOfFrame(); 用于本帧渲染完
yield return new WaitForEndOfFrame(); // 本帧渲染完后
StartCoroutine/StopCoroutineInvoke的更多相关文章
- 关于StartCoroutine的简单线程使用
StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,但是在unity中有些元素是不能操作的.这个时候可以使用协程来完成. 使 ...
- 9. MonoBehaviour.StartCoroutine 开始协同程序
function StartCoroutine (routine : IEnumerator) : Coroutine 描述:开始协同程序. 一个协同程序在执行过程中,可以在任意位置使用yield语句 ...
- 使用startCoroutine制定倒计时
使用startCoroutine制定倒计时 using UnityEngine; using System.Collections; public class TimerCoroutine : Mon ...
- 【错误总结1:unity StartCoroutine 报 NullReferenceException 错误】
今天在一个项目中,写了一个单例的全局类,该类的作用是使用协程加载场景.但在StartCoroutine 这一步报了NullReferenceException 的错.仔细分析和搜索之后,得到错误原因. ...
- StartCoroutine 和 StopCoroutine
我的Unity版本是2017.2.0p4(64-bit) StartCoroutine的两个版本: StartCoroutine(string methodName) StartCoroutine(I ...
- 问题记录,StartCoroutine(“str")问题
StartCoroutine参数为函数字符串名,运行时出错,错误是:无法启动协程函数. 调用格式如下: gameManager.StartCoroutine(LuaOnLevelwasloaded() ...
- unity, StartCoroutine and StopCoroutine
startCoroutine("func",1.0f)可以用stopCoroutine("func")来停. startCoroutine(func(1.0f) ...
- unity关于StartCoroutine的简单线程使用
StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,但是在unity中有些元素是不能操作的.这个时候可以使用协程来完成. 使 ...
- StartCoroutine的使用
StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,可是在unity中有些元素是不能操作的.这个时候能够使用协程来完毕. 使 ...
随机推荐
- linux 里 /etc/passwd 、/etc/shadow和/etc/group 文件内容解释
•/etc/passwd文件用于存放用户账户信息,每行代表一个账户,每个账户的各项信息用冒号分割,例如: root:x:::root:/root:/bin/bash username:password ...
- TabHost结合RadioButton实现主页的导航效果
布局文件的设置,如下 <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:androi ...
- C# 匿名方法 委托 Action委托 Delegate委托
原文地址:https://msdn.microsoft.com/zh-cn/library/bb882516.aspx 匿名函数是一个“内联”语句或表达式,可在需要委托类型的任何地方使用. 可以使用匿 ...
- E - Currency Exchange
题目大意: 汇率问题,有N个银行,他们之间有一些汇率,某个人手里面拿着其中一种钱,然后在这里面兑换钱币,当然兑换是有汇率和手续费的,然后经过一系列兑换后问手里面的钱是不是能增加? ;; i<le ...
- 10th day
貌似有几天没写博客了额.... 现在学习MySQL数据库,难度并不是很大,只是需要记忆的知识点比较多,好多语法之类的,比较容易混淆,而且老师讲课的速度还是蛮快的,虽然部分同学觉得听起来有点吃力,不过我 ...
- Fiddler 抓包 教程
Fiddler的基本介绍 Fiddler的官方网站: www.fiddler2.com Fiddler官方网站提供了大量的帮助文档和视频教程, 这是学习Fiddler的最好资料. Fiddler是最 ...
- Lucene多字段搜索
最近在学习Lucene的过程中遇到了需要多域搜索并排序的问题,在网上找了找,资料不是很多,现在都列出来,又需要的可以自己认真看看,都是从其他网站粘贴过来的,所以比较乱,感谢原创的作者们! 使用 ...
- POJ 2431 Expedition (STL 优先权队列)
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8053 Accepted: 2359 Descri ...
- CF 295E Yaroslav and Points(Splay)
题目大意: 两个操作 1 id op 把id的位置+op 2 id op 查询在[id.op]之间的全部的数的差 思路: 关键是pushup函数. 自己退一下会发现.跟区间的总和,区间的节点个数有 ...
- MySQL更新时Error Code:1093和Error Code:1175的解决办法
Error Code: 1093. You can't specify target table 'ws_product' for update in FROM clause 这个是我们在使用upda ...