-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWalrusScript.cs
155 lines (147 loc) · 4.52 KB
/
WalrusScript.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
public class WalrusScript : MonoBehaviour
{
List<GameObject> platformsList;
public GameObject[] platformsArray;
public Animator animCtrl;
public float tickT;
bool canTick;
public float sinkSpeed;
int num;
public int winNumber;
bool canSink;
bool canAttack;
public float attackInterval;
Vector3 attackPos;
PlayerController player;
public Transform homePos;
float lerpT;
public float lerpSpeed;
public GameObject flag;
bool shouldAttack;
public float maxLerpDist;
Vector3 lookAt;
bool beatYet;
float beatYPos;
bool canSwitch;
public Slider progressSlider;
public float startDelay;
bool canWork;
GameObject platformObj;
int currentLvl;
bool startedYet;
public Color sliderColor;
void Start()
{
platformsList = new List<GameObject>();
player = FindObjectOfType<PlayerController>();
canTick = true;
canAttack = true;
canSwitch = true;
transform.position = homePos.position;
beatYPos = homePos.position.y;
ResetList();
}
void Wait()
{
canWork = true;
lerpT = 0f;
}
void Update()
{
currentLvl = player.currentLevel;
if (!startedYet && currentLvl == 12)
{
Invoke(nameof(Wait), startDelay);
startedYet = true;
}
if (player.inWater | player.hitEnemy)
{
transform.position = homePos.position;
}
if (canWork)
{
if (!beatYet)
{
progressSlider.value = platformsList.Count / (float)platformsArray.Length;
progressSlider.minValue = winNumber / (float)platformsArray.Length;
if (canTick)
{
Invoke(nameof(DropPlatform), tickT);
canTick = false;
}
SinkPlatform();
lookAt = new Vector3(player.transform.position.x, .55f, player.transform.position.z);
if (canAttack)
{
Invoke(nameof(Attack), attackInterval);
lerpT = .1f;
lerpSpeed *= -1f;
canAttack = false;
}
transform.position = Vector3.Lerp(homePos.position, attackPos, lerpT);
lerpT += lerpSpeed * Time.deltaTime;
if (lerpT >= maxLerpDist && canSwitch)
{
lerpSpeed *= -1f;
canSwitch = false;
}
if (lerpT < .1f)
{
animCtrl.SetBool("isRunning", false);
transform.LookAt(lookAt);
canSwitch = true;
}
}
else
{
beatYPos -= sinkSpeed * Time.deltaTime;
transform.position = new Vector3(homePos.position.x, beatYPos, homePos.position.z);
}
}
}
void DropPlatform()
{
if (platformsList.Count > winNumber)
{
num = Random.Range(0, platformsList.Count - 1);
platformObj = platformsList[num];
platformsList.RemoveAt(num);
}
else
{
flag.SetActive(true);
beatYet = true;
progressSlider.transform.Find("Background").GetComponent<Image>().color = Color.green;
}
canTick = true;
}
void SinkPlatform()
{
if (platformObj != null)
{
platformObj.transform.Translate(Vector3.forward * sinkSpeed * Time.deltaTime);
}
}
public void ResetList()
{
platformsList.Clear();
beatYet = false;
transform.position = homePos.position;
progressSlider.transform.Find("Background").GetComponent<Image>().color = sliderColor;
foreach (var platform in platformsArray)
{
platformsList.Add(platform);
platform.SetActive(true);
platform.transform.position = new Vector3(platform.transform.position.x, -.5f, platform.transform.position.z);
}
}
void Attack()
{
canAttack = true;
attackPos = new Vector3(player.transform.position.x, .55f, player.transform.position.z);
animCtrl.SetBool("isRunning", true);
}
}