Repository navigation
Expand file tree
/
Copy pathEnterManager.cs
More file actions
84 lines (76 loc) · 2.31 KB
/
Copy pathEnterManager.cs
File metadata and controls
84 lines (76 loc) · 2.31 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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class EnterManager : MonoBehaviour
{
private int count = 0;
private bool started = false;
public TextMesh countText;
void Start()
{
this.countText.gameObject.SetActive(false);
PlayerPrefs.SetInt("finished", 0);
}
void Update()
{
}
private void OnTriggerExit(Collider other)
{
IEnumerator countdown = CountdownCoroutine();
if (other.gameObject.name == "Main Camera")
{
if (other.gameObject.transform.position.z >= 3)
{
if (!started)
{
StartCoroutine(countdown);
started = true;
GameObject spawner = GameObject.Find("Spawner");
spawner.GetComponent<Spawner>().enabled = true;
}
} else
{
reload();
}
}
}
IEnumerator CountdownCoroutine()
{
this.countText.gameObject.SetActive(true);
while (PlayerPrefs.GetInt("finished") != 1)
{
count++;
this.countText.text = (count / 60).ToString("00") + ":" + (count % 60).ToString("00");
yield return new WaitForSeconds(1);
}
checkHighscore(count);
}
public void reload()
{
string currentSceneName = SceneManager.GetActiveScene().name;
SceneManager.LoadScene(currentSceneName);
}
public void checkHighscore(int count)
{
string highscore = PlayerPrefs.GetString("highscore");
if (!highscore.Equals(""))
{
int score = Int32.Parse(highscore.Split(':')[1]) + Int32.Parse(highscore.Split(':')[0]) * 60;
if (count < score)
{
PlayerPrefs.SetString("highscore", (count / 60).ToString("00") + ":" + (count % 60).ToString("00"));
countText.text = "Highscore";
}
else
{
this.countText.gameObject.SetActive(false);
}
} else
{
PlayerPrefs.SetString("highscore", (count / 60).ToString("00") + ":" + (count % 60).ToString("00"));
countText.text = "Highscore";
}
}
}