Last active
November 19, 2018 14:25
-
-
Save jordyhenry/fa6dfc8d44f7e41bff3e735dfeaddde9 to your computer and use it in GitHub Desktop.
This file contains 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 System.Collections; | |
using UnityEngine; | |
public class SimpleGrowUp : MonoBehaviour | |
{ | |
Coroutine coroutine; | |
//First keyframe of the animation | |
public Vector3 startScale; | |
//Last keyframe of the animation | |
public Vector3 endScale; | |
//Animation duration | |
public float animationTime = 2f; | |
private void Update() | |
{ | |
if(Input.GetKeyDown(KeyCode.Space)) | |
{ | |
if(coroutine != null) | |
StopCoroutine(coroutine); | |
coroutine = StartCoroutine(IEScale()); | |
} | |
} | |
private IEnumerator IEScale() | |
{ | |
float t = 0; | |
do | |
{ | |
//Calculation the current time percentage in a 0 to 1 scale | |
float percent = t / animationTime; | |
//using that percerntage to calculate the Lerp value | |
transform.localScale = Vector3.Lerp(startScale, endScale, percent); | |
t += Time.deltaTime; | |
//Wait the next frame to run the next loop | |
yield return null; | |
} while (t <= animationTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment