Created
September 11, 2016 02:51
-
-
Save unitycoder/eb3833e1bda8ac2c04fca2a3eb343cb0 to your computer and use it in GitHub Desktop.
Camera Position Lerp With AnimationCurve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| public class CameraLerp : MonoBehaviour | |
| { | |
| public float duration = 2; | |
| public AnimationCurve speedCurve = AnimationCurve.EaseInOut(0,0,1,1); | |
| void Start() | |
| { | |
| StartCoroutine(FlyToTarget()); | |
| } | |
| IEnumerator FlyToTarget() | |
| { | |
| var startPos = transform.position; | |
| var targetPos = Vector3.one*5; | |
| for (float timer = 0; timer < duration; timer += Time.deltaTime) | |
| { | |
| transform.position = Vector3.Lerp(startPos, targetPos, speedCurve.Evaluate(timer / duration)); | |
| yield return null; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment