-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenDrawerSpecial.cs
122 lines (95 loc) · 2.77 KB
/
OpenDrawerSpecial.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OpenDrawerSpecial : MonoBehaviour
{
public Animator ANI;
public GameObject openText;
public GameObject closedText;
public AudioSource openSound;
public AudioSource closeSound;
private bool open;
private bool inReach;
public int randomNumber;
public GameObject loot1;
public GameObject loot2;
public GameObject loot3;
public GameObject drawer;
public bool fix;
void Start()
{
randomNumber = UnityEngine.Random.Range(0, 2);
Debug.Log(randomNumber);
openText.SetActive(false);
closedText.SetActive(false);
loot1.SetActive(false);
loot2.SetActive(false);
loot3.SetActive(false);
ANI.SetBool("open", false);
ANI.SetBool("close", false);
open = false;
}
void OnTriggerEnter(Collider other)
{
if(!loot1.activeInHierarchy || !loot2.activeInHierarchy || !loot3.activeInHierarchy){
if(randomNumber == 0){
loot1.SetActive(true);
}
if(randomNumber == 1){
loot2.SetActive(true);
}
if(randomNumber == 2){
loot3.SetActive(true);
}
}
fix = drawer.GetComponent<LookAtDrawer>().isFixed;
if (other.gameObject.tag == "Reach" && !open && fix == true)
{
inReach = true;
openText.SetActive(true);
closedText.SetActive(false);
}
else if (other.gameObject.tag == "Reach" && !open && fix == false)
{
inReach = true;
openText.SetActive(false);
closedText.SetActive(false);
}
else if (other.gameObject.tag == "Reach" && open && fix == true)
{
inReach = true;
closedText.SetActive(true);
openText.SetActive(false);
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Reach")
{
inReach = false;
openText.SetActive(false);
closedText.SetActive(false);
}
}
void Update()
{
if (!open && inReach && Input.GetButtonDown("Interact"))
{
openSound.Play();
ANI.SetBool("open", true);
ANI.SetBool("close", false);
open = true;
openText.SetActive(false);
inReach = false;
}
else if (open && inReach && Input.GetButtonDown("Interact"))
{
closeSound.Play();
ANI.SetBool("open", false);
ANI.SetBool("close", true);
open = false;
closedText.SetActive(false);
inReach = false;
}
}
}