Linear interpolation known as Lerp. Why it’s called Lerp I do not know! Is it L for “Linear” with an erp for ‘ERPolation? Who knows.
Take three inputs. A start value, and end value, and a percentage value between the start and the end.
// In this case, result = 4 float result = Mathf.Lerp (3f, 5f, 0.5f); Vector3 from = new Vector3 (1f, 2f, 3f); Vector3 to = new Vector3 (5f, 6f, 7f); // Here result = (4, 5, 6) Vector3 result = Vector3.Lerp (from, to, 0.75f);
Simple.
Lerp can make a cool lighting effect. With an exponential intensity to an upper limit:
//Making a Lerp light GameObject lightGameObject = new GameObject("The Light"); Light lightComp = lightGameObject.AddComponent<Light>(); lightComp.color = Color.blue; lightGameObject.transform.position = new Vector3(0, 5, 0); lightGameObject.intensity = Mathf.Lerp(lightGameObject.intensity, 8f, 0.5f * Time.deltaTime);