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的更多相关文章

  1. unity3d Vector3.Lerp解析

    Vector3.Lerp:http://www.ceeger.com/Script/Vector3/Vector3.Lerp.html 手册中描述的不是很详细,什么叫“按照数字t在from到to之间插 ...

  2. Vector3.Lerp 插值

    Vector3.Lerp 插值 static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3 Description ...

  3. 对Vector3.Lerp 插值的理解

    有时,我们在做游戏时会发现有些跟随动作不够圆滑或者需要一个缓冲的效果,这时,一般会考虑到插值.所以对插值的理解是必需的.(比如摄像机跟随主角) 插值是数学上的一个概念,在这里用公式表示就是:from  ...

  4. 如何正确的使用Lerp In Unity

    摘要 本文探讨如何用lerp实现近似的匀速旋转,当然如果运用本文给出的方法,使用slerp则可以实现匀速旋转,并指出Unity官方lerp示例代码的一些缺陷. 现有问题 比如四元数Lerp API: ...

  5. Unity的Lerp函数实现缓动

    在Unity里面Lerp函数可以实现缓动效果 下面例子实现点光源的移动 在场景中创建好一个平面,一个点光源,我在这里随便放了一个模型. 然后新建c#脚本,代码如下: using UnityEngine ...

  6. [UE4]时间轴线TimeLine,Lerp插值

    一.TimeLine时间轴线 勾选“User Last Keyframe”表示使用时间轴最后一个关键帧所在时间点作为结束时间,而不是使用设置的5秒作为结束时间点. 二.Lerp插值 Lerp插值一般与 ...

  7. UE4 材质Lerp节点解疑

    转自:http://www.manew.com/thread-46268-1-1.html 1.A是一个灰色,B是一个红色,Alpha是一个颜色图 A到B是0到1,也就是黑到白,所以,alpha图,黑 ...

  8. Unity3d 插值Lerp与Slerp

    Lerp Lerp表示线性插值. Slerp 球形插值在Vector3.Quaternion等类都有使用,一般多在Quaternion的旋转操作时使用.

  9. Shader中的lerp

    下面解释下什么是lerp的功能: 官方解释 float lerp(float a, float b, float w) {   return a + w*(b-a); } 木有看懂 我的解释:把上面的 ...

  10. 关于 lerp();

    value lerp(value s, value a, value b ); 该函数返回的值为:a + s * (b - a) ,是一个处于 [a, b] 之间的值. 当s=0, 该函数返回a :当 ...

随机推荐

  1. coredump之栈溢出

    1.栈溢出引发的core往往出现出现在递归调用中. gdb时看到的特征是: 栈缺失,当前栈地址不可读. 根据栈是逆向生长的特点(栈逆向生长,所以很容易出现类似数组溢出覆盖率函数返回地址,导致函数退出地 ...

  2. Java线程的wait(), notify()和notifyAll()

    Java线程生命周期 类java.lang.Thread包含一个静态的State enum用于定义每种可能的状态. 在任意的时间点, 线程会处于以下的状态之一: NEW – 新创建的线程, 还未启动( ...

  3. GIS地理处理脚本案例教程——批量栅格分割-批量栅格裁剪-批量栅格掩膜-深度学习样本批量提取

    GIS地理处理脚本案例教程--批量栅格分割-批量栅格裁剪-批量栅格掩膜-深度学习样本批量提取 商务合作,科技咨询,版权转让:向日葵,135-4855_4328,xiexiaokui#qq.com 关键 ...

  4. docker安装并运行mongo

    拉镜像: [mall@VM_0_7_centos ~]$ sudo docker pull mongo:3.2 [sudo] password for mall: 3.2: Pulling from ...

  5. [转]使用apt安装nodejs10

    使用apt安装nodejs10 链接地址:https://blog.csdn.net/sunhaobo1996/article/details/80340513

  6. [LeetCode] 219. Contains Duplicate II 包含重复元素 II

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...

  7. [LeetCode] 403. Frog Jump 青蛙跳

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  8. android基础---->WebView的使用

    webView的使用 我们通过一个小的测试程序来体会webView的简单使用,项目结构如下:

  9. LeetCode 187. 重复的DNA序列(Repeated DNA Sequences)

    187. 重复的DNA序列 187. Repeated DNA Sequences 题目描述 All DNA is composed of a series of nucleotides abbrev ...

  10. 数据分析——matplotlib的用法

    Matplotlib是一个强大的Python绘图和数据可视化的工具包.数据可视化也是我们数据分析的最重要的工作之一,可以帮助我们完成很多操作,例如:找出异常值.必要的一些数据转换等.完成数据分析的最终 ...