-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarManager.cs
80 lines (77 loc) · 2.35 KB
/
StarManager.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
using UnityEngine;
public class StarManager : MonoBehaviour
{
public StarScript[] stars;
public float starRadius;
GameObject starObject;
public Transform pos;
public LayerMask starMask;
Collider[] starColliders;
public int starCount;
bool gavePoints;
public Material goldPenguinMat;
public SkinnedMeshRenderer meshR;
Material[] meshMats;
UIManager UIManager;
[TextArea(2, 5)]
public string firstStarText;
[TextArea(2, 5)]
public string lastStarText;
void Start()
{
starCount = 0;
UIManager = FindObjectOfType<UIManager>();
for (int i = 0; i < stars.Length; i++)
{
if (PlayerPrefs.GetInt("Star" + i, 0) == 1)
{
stars[i].gameObject.SetActive(false);
starCount++;
}
}
}
void Update()
{
starColliders = Physics.OverlapSphere(pos.position, starRadius, starMask);
if (starColliders.Length > 0)
{
if (starColliders[0].CompareTag("Star"))
{
starObject = starColliders[0].gameObject;
for (int i = 0; i < stars.Length; i++)
{
if (stars[i].gameObject == starObject)
{
PlayerPrefs.SetInt("Star" + i, 1);
stars[i].Found();
if (!gavePoints)
{
starCount++;
gavePoints = true;
Invoke(nameof(Wait), stars[i].waitT);
if (starCount == 1)
{
UIManager.FirstStar(firstStarText);
}
if (starCount == 6)
{
UIManager.FirstStar(lastStarText);
}
}
}
}
}
}
if (starCount >= 6)
{
meshMats = meshR.materials;
meshMats[0] = goldPenguinMat;
meshMats[1] = goldPenguinMat;
meshR.materials = meshMats;
}
}
void Wait()
{
gavePoints = false;
}
}