AnimationScript.cs
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using UnityEngine;
using System.Collections;
public class AnimationScript : 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;
}
}
}
}
}