-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiplebuttongate.cs
112 lines (89 loc) · 2.87 KB
/
multiplebuttongate.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
using UnityEngine;
public class multiplebuttongate : MonoBehaviour
{
private SpriteRenderer spriteRenderer;
public bool IsOpen = false;
public Sprite Open;
public Sprite Closed;
public ParticleSystem OpenParticles;
private GameObject[] buttons;
public KeyCode interactKey = KeyCode.E;
public bool GhostInRadius = false;
GameObject Ghost;
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
//spriteRenderer.color = Color.blue;
Ghost = FindObjectOfType<PlayerController>().gameObject;
}
void Update()
{
bool allButtonsGreen = CheckAllButtonsGreen();
if (allButtonsGreen)
{
if(!IsOpen)
{
FindObjectOfType<AudioManager>().Play("DoorOpen");
spriteRenderer.sprite = Open;
OpenParticles.Play();
IsOpen = true;
}
}
else
{
if (IsOpen)
{
FindObjectOfType<AudioManager>().Play("DoorClose");
}
spriteRenderer.sprite = Closed; // Change to desired default color
IsOpen = false;
}
if(GhostInRadius)
{
if (Ghost.gameObject.GetComponent<PlayerController>().GhostMode && IsOpen)
{
FindObjectOfType<LevelManager>().WinThisLevel();
Debug.Log("Level Complete"); // Display game over message in console
}
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Ghost")
{
//print("GHOSTT");
if (other.gameObject.GetComponent<PlayerController>().GhostMode && IsOpen)
{
GhostInRadius = true;
this.gameObject.GetComponent<Renderer>().material = FindObjectOfType<MySceneManager>().HighlightedMat;
}
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.tag == "Ghost")
{
if (other.gameObject.GetComponent<PlayerController>().GhostMode && IsOpen)
{
//print("GHOSTT");
GhostInRadius = false;
if(FindObjectOfType<MySceneManager>() != null)
{
this.gameObject.GetComponent<Renderer>().material = FindObjectOfType<MySceneManager>().DefaultMat;
}
}
}
}
bool CheckAllButtonsGreen()
{
GameObject[] buttons = GameObject.FindGameObjectsWithTag("Button");
foreach (GameObject button in buttons)
{
if(button.GetComponent<ColorChangeOnTrigger>().IsPressed != true)
{
return false;
}
}
return true;
}
}