Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Mathf.Lerp

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function Lerp(from: float, to: float, t: float): float;
public static float Lerp(float from, float to, float t);
public static def Lerp(from as float, to as float, t as float) as float

Description

Interpolates between a and b by t. t is clamped between 0 and 1.

When t = 0 returns from. When t = 1 return to. When t = 0.5 returns the average of a and b.

	// Fades from minimum to maximum in one second

var minimum = 10.0; var maximum = 20.0;

function Update () { transform.position = Vector3(Mathf.Lerp(minimum, maximum, Time.time), 0, 0); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public float minimum = 10.0F;
    public float maximum = 20.0F;
    void Update() {
        transform.position = new Vector3(Mathf.Lerp(minimum, maximum, Time.time), 0, 0);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public minimum as float = 10.0F

	public maximum as float = 20.0F

	def Update() as void:
		transform.position = Vector3(Mathf.Lerp(minimum, maximum, Time.time), 0, 0)