Skip to content

Instantly share code, notes, and snippets.

@jordyhenry
Last active November 19, 2018 14:25
Show Gist options
  • Save jordyhenry/fa6dfc8d44f7e41bff3e735dfeaddde9 to your computer and use it in GitHub Desktop.
Save jordyhenry/fa6dfc8d44f7e41bff3e735dfeaddde9 to your computer and use it in GitHub Desktop.
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