-
Notifications
You must be signed in to change notification settings - Fork 0
/
WormScript.cs
68 lines (65 loc) · 2.29 KB
/
WormScript.cs
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
using UnityEngine;
using System.Collections;
public class WormScript : MonoBehaviour {
public GameObject wormEntrance, wormExit, Worm, wormOverlayEntrance, wormOverlayExit, camPos;
public float speed = 2f;
private float animTime = 0.8f;
public float gap = 2f;
private bool canMove = false;
private Animator anim, anim2;
public Camera Camera;
public float shake = 0f;
public float shakeAmount = 0.7f;
public float decrease = 1f;
Vector3 camOrigPos = Vector3.zero;
public float shakeMore = 4f;
void Start () {
camPos = GameObject.Find("Cameraposition");
anim = wormEntrance.GetComponent<Animator>();
anim2 = wormExit.GetComponent<Animator>();
wormExit.SetActive(false);
StartCoroutine("timer");
}
void Update () {
camOrigPos = camPos.transform.position;
if (shake > 0f)
{
Vector2 rndShake = Random.insideUnitCircle * shakeAmount;
Camera.transform.localPosition = new Vector3(rndShake.x, rndShake.y - 0.3f, camOrigPos.z);
shake -= Time.deltaTime * decrease;
}
else
{
shake = 0.0f;
Camera.transform.position = camOrigPos;
}
if (canMove)
{
Worm.transform.Translate(Vector3.up * (speed) * Time.deltaTime);
}
}
IEnumerator timer()
{
shake = 1f;
yield return new WaitForSeconds(animTime);
anim.SetInteger("state", 1);
wormOverlayEntrance.SetActive(true);
canMove = true;
yield return new WaitForSeconds(gap / 6);
shakeAmount *= shakeMore;
yield return new WaitForSeconds(gap / 6);
yield return new WaitForSeconds(gap / 4);
wormExit.SetActive(true);
yield return new WaitForSeconds(gap / 4);
wormOverlayExit.SetActive(true);
yield return new WaitForSeconds(gap / 4);
anim.SetInteger("state", 2);
yield return new WaitForSeconds(animTime / 2);
wormOverlayEntrance.SetActive(false);
yield return new WaitForSeconds(animTime / 2);
anim2.SetInteger("state", 2);
yield return new WaitForSeconds(animTime);
wormOverlayExit.SetActive(false);
Destroy(gameObject);
}
}