首页 技术 正文
技术 2022年11月14日
0 收藏 574 点赞 2,974 浏览 1061 个字

关于 int Mathf.PingPong(t, length); 原理,相当于

#include <iostream>
#include <vector>int test(int t, int length)
{
if(t / length % == )
return length - t % length;
else
return t % length;
}int main()
{
int length = ;
std::vector<int> vect{,,,,,,,,};
for(auto& item : vect)
{
std::cout<<test(item,length)<<",";
}
}

说明参见:http://forum.unity3d.com/threads/mathf-repeat-vs-mathf-pingpong.1388/

类似的还有 Color.Lerp    / Vector3.Lerp

在 Update 里调用  Color32.Lerp(colorWhite, colorBlack, Time.time); 一般是指在1秒钟内完成变色,但如果一开始Time.time就不等于0,则结果不是这样,假设Time.time开始执行时就>1,则执行到此代码时,立即变色,如下:

float time = ;void Update () {
time += Time.deltaTime;
if(time>)
{
Color c = Color32.Lerp(Color.white, Color.black, Time.time);
Debug.Log(c.r + "," + c.g + "," + c.b);
gameObject.GetComponent<Image>().color = c;
}
}

如果要使用3秒时间完成变色,则需要如下代码:

float time = ;void Update () {
gameObject.GetComponent<Image>().color = Color32.Lerp(Color.white, Color.black, time);
time += Time.deltaTime / ;
}

Time.time是指

unity 协程

调用 StartCoroutine ,相当于创建并进入了另一个线程,并执行其中的函数,直到遇到第一个 yield return,此时协程暂停,然后将程序执行权返还给调用函数,什么时候恢复执行是根据 yield return 后面的参数决定的,如果是 yield return null; 表示一帧后恢复,如果是 yield return new WaitForSeconds(3); 表示3秒后恢复,如果后面跟一个对象,则该对象不为 nil 时恢复 。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,496
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,743
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,134
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298