Lerp
Lerp,就是返回两个值之间的插值,一般有三个参数。第一个参数为初始值,第二个参数为最终值,插值为0~1d的一个浮点数值,为0时为初始值,1时为最终值,为0到1之间的数值时返回一个混合数值。若第三个参数为Time.daltaTime,这返回随时间推移的一个值。
以Color.Lerp为例
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System; public class ColorChange : MonoBehaviour
{ public Image image;
public float speed;
private Color old;
private Color change;
// Use this for initialization
void Awake ()
{
old = Color.white;
change = Color.green;
image.color = old;
speed=0.5f;
}
void Update()
{ float a = speed * Time.deltaTime; if (this.GetComponent<Image>().color.b > 0.1f)
{
this.GetComponent<Image>().color = Color.Lerp(this.GetComponent<Image>().color, Color.black, a);
}
else
this.GetComponent<Image>().color = change;
}
}
运行之后,白色ugui Image会由白色逐渐变成灰黑色
除了Color之外还有
Material.Lerp
public void Lerp(Material start, Material end, float t);
通常,您想要差值的两个材质是相同的(使用相同的着色器和纹理) 除了颜色和浮点数。然后您可以使用 Lerp 做它们之间的混合。
Color32.Lerp
Quaternion.Lerp
Interpolates between a and b by t and normalizes the result afterwards. The parameter t is clamped to the range [0, 1].
通过t值from向to之间插值,并且规范化结果。
This is faster than Slerp but looks worse if the rotations are far apart.
这个比Slerp更快但是如果旋转较远看起来就比较差。
Mathf.Lerp
Interpolates a towards b by t. t is clamped between 0 and 1.
基于浮点数t返回a到b之间的插值,t限制在0~1之间。
When t = 0 returns from. When t = 1 return to. When t = 0.5 returns the average of a and b.
当t = 0返回from,当t = 1 返回to。当t = 0.5 返回from和to的平均值。
Vector3.Lerp
可以用来控制游戏对象大小,位置什么的,因为,transfrom中的position跟scale,rotation都是一组Vector3
Vector2.Lerp
Vector4.Lerp
Lerp的更多相关文章
- unity3d Vector3.Lerp解析
Vector3.Lerp:http://www.ceeger.com/Script/Vector3/Vector3.Lerp.html 手册中描述的不是很详细,什么叫“按照数字t在from到to之间插 ...
- Vector3.Lerp 插值
Vector3.Lerp 插值 static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3 Description ...
- 对Vector3.Lerp 插值的理解
有时,我们在做游戏时会发现有些跟随动作不够圆滑或者需要一个缓冲的效果,这时,一般会考虑到插值.所以对插值的理解是必需的.(比如摄像机跟随主角) 插值是数学上的一个概念,在这里用公式表示就是:from ...
- 如何正确的使用Lerp In Unity
摘要 本文探讨如何用lerp实现近似的匀速旋转,当然如果运用本文给出的方法,使用slerp则可以实现匀速旋转,并指出Unity官方lerp示例代码的一些缺陷. 现有问题 比如四元数Lerp API: ...
- Unity的Lerp函数实现缓动
在Unity里面Lerp函数可以实现缓动效果 下面例子实现点光源的移动 在场景中创建好一个平面,一个点光源,我在这里随便放了一个模型. 然后新建c#脚本,代码如下: using UnityEngine ...
- [UE4]时间轴线TimeLine,Lerp插值
一.TimeLine时间轴线 勾选“User Last Keyframe”表示使用时间轴最后一个关键帧所在时间点作为结束时间,而不是使用设置的5秒作为结束时间点. 二.Lerp插值 Lerp插值一般与 ...
- UE4 材质Lerp节点解疑
转自:http://www.manew.com/thread-46268-1-1.html 1.A是一个灰色,B是一个红色,Alpha是一个颜色图 A到B是0到1,也就是黑到白,所以,alpha图,黑 ...
- Unity3d 插值Lerp与Slerp
Lerp Lerp表示线性插值. Slerp 球形插值在Vector3.Quaternion等类都有使用,一般多在Quaternion的旋转操作时使用.
- Shader中的lerp
下面解释下什么是lerp的功能: 官方解释 float lerp(float a, float b, float w) { return a + w*(b-a); } 木有看懂 我的解释:把上面的 ...
- 关于 lerp();
value lerp(value s, value a, value b ); 该函数返回的值为:a + s * (b - a) ,是一个处于 [a, b] 之间的值. 当s=0, 该函数返回a :当 ...
随机推荐
- 视频色彩空间RGB、YUV、YCbCr
RGB.YUV和YCbCr都是人为规定的彩色模型或颜色空间(有时也叫彩色系统或彩色空间).它的用途是在某些标准下用通常可接受的方式对彩色加以描述.本质上,彩色模型是坐标系统和子空间的阐述. RGB R ...
- node 部署教程二
转:https://www.cnblogs.com/yesyes/p/7168449.html 这篇文章主要介绍如何在服务端跑vuejs的项目,如果上一篇教程你成功输出了hello world,那这一 ...
- 测量MySQL的表达式和函数的速度
测量MySQL的表达式和函数的速度,可以调用benchmark()函数.语法格式是benchmark(loop_count,expr).运行的返回值是0,但是mysql会打印一行显示语句大概要执行多长 ...
- ios开发 需要注意的地方、注意事项
/* 一.LaunchScreenLaunchScreen产生原因:代替之前的启动图片好处:1.可以展示更多的东西2.可以只需要出一个尺寸的图片. 启动图片的优先级启动图片 < LaunchSc ...
- [LeetCode] 52. N-Queens II N皇后问题 II
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...
- [LeetCode] 203. Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- [LeetCode] 463. Island Perimeter 岛的周长
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...
- 算法练习之二叉树的最大深度,二叉树的层次遍历 II
1.二叉树的最大深度 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例:给定二叉树 [3,9,20,null,n ...
- 使用Delphi开发linux应用
对于很多喜欢使用delphi做开发的人都希望delphi能够支持linux平台的开发,终于在delphi10.2版本中,delphi开始支持linux平台的开发了.在这里写一下Linux开发环境的配置 ...
- 永久解决Sublime包管理package control 打开install package报错 There are no packages available for installation
很多用户在使用sumblime安装插件的时候,打开package control的install package会出现报错:There are no packages available for in ...