首页 » Web前端 » unityphp乱码技巧_Unity编码篇 协程

unityphp乱码技巧_Unity编码篇 协程

访客 2024-12-13 0

扫一扫用手机浏览

文章目录 [+]

在unity中, Coroutine是返回 IEnumerator 的 C# 函数 , 必须利用 StartCoroutine 方法开启协程 , 必须继续 MonoBehavior .

常用函数 :

unityphp乱码技巧_Unity编码篇 协程

StartCoroutine : 启动一个协程 ;

unityphp乱码技巧_Unity编码篇 协程
(图片来自网络侵删)

StopCoroutine : 中指一个协程 ;

StopAllCoroutine : 终止所有协程 ;

WaitForSeconds : 等待多少秒 ;

WaitForFixedUpdate : 等待直到下一次 FixedUpdate 调用 ;

下面写一小段代码吧

记得上次我们写了定时器每隔一段韶光,cube移动 ,本日我们用协程来实现

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class CoroutineTest : MonoBehaviour

{

//Coroutine move;

private void Start()

{

// 1.用这种办法字符串办法开启协程 , 也可以用这个办法关闭 , 但是无法带参数

StartCoroutine(\"大众Move\"大众);

// 2.用这种办法开启协程 , 可以带参数 , 但是必须要先获取这个move工具 , 关闭的时候须要关闭这个move工具

//move = StartCoroutine(Move());

}

IEnumerator Move()

{

transform.GetComponent<MeshRenderer>().material.color = Color.red;

yield return new WaitForSeconds(3);

transform.GetComponent<MeshRenderer>().material.color = Color.green;

}

private void OnDestroy()

{

StopCoroutine(\"大众Move\"大众);

// StopCoroutine(move);

}

}

请点击输入图片描述

刚开始cube是赤色的 , 3s后变为绿色 .

视频加载中...

来日诰日开始,为大家先容 UGUI , 游戏界面好看的画面是怎么来的呢 , 来日诰日带大家一起学习吧 .

标签:

相关文章