Created
September 23, 2018 08:22
-
-
Save 3dln/a73e5f3204db5dfba82b1d4dae254071 to your computer and use it in GitHub Desktop.
Adds scale, rotate and move animation loops to the game objects
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 UnityEngine; | |
using System.Collections; | |
public class ModelAnimation : MonoBehaviour { | |
public bool isAnimated = false; | |
public bool isRotating = false; | |
public bool isFloating = false; | |
public bool isScaling = false; | |
public Vector3 rotationAngle; | |
public float rotationSpeed; | |
public float floatSpeed; | |
private bool goingUp = true; | |
public float floatRate; | |
private float floatTimer; | |
public Vector3 startScale; | |
public Vector3 endScale; | |
private bool scalingUp = true; | |
public float scaleSpeed; | |
public float scaleRate; | |
private float scaleTimer; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
if(isAnimated) | |
{ | |
if(isRotating) | |
{ | |
transform.Rotate(rotationAngle * rotationSpeed * Time.deltaTime); | |
} | |
if(isFloating) | |
{ | |
floatTimer += Time.deltaTime; | |
Vector3 moveDir = new Vector3(0.0f, 0.0f, floatSpeed); | |
transform.Translate(moveDir); | |
if (goingUp && floatTimer >= floatRate) | |
{ | |
goingUp = false; | |
floatTimer = 0; | |
floatSpeed = -floatSpeed; | |
} | |
else if(!goingUp && floatTimer >= floatRate) | |
{ | |
goingUp = true; | |
floatTimer = 0; | |
floatSpeed = +floatSpeed; | |
} | |
} | |
if(isScaling) | |
{ | |
scaleTimer += Time.deltaTime; | |
if (scalingUp) | |
{ | |
transform.localScale = Vector3.Lerp(transform.localScale, endScale, scaleSpeed * Time.deltaTime); | |
} | |
else if (!scalingUp) | |
{ | |
transform.localScale = Vector3.Lerp(transform.localScale, startScale, scaleSpeed * Time.deltaTime); | |
} | |
if(scaleTimer >= scaleRate) | |
{ | |
if (scalingUp) { scalingUp = false; } | |
else if (!scalingUp) { scalingUp = true; } | |
scaleTimer = 0; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment