Repository navigation
Expand file tree
/
Copy pathDoorScript.cs
More file actions
150 lines (135 loc) · 4.03 KB
/
Copy pathDoorScript.cs
File metadata and controls
150 lines (135 loc) · 4.03 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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DoorScript : MonoBehaviour {
//HUD BUTTON
public GameObject buttonToPress;
public Image spriteHUD;
[Range (0,1)]
public float alphaSpeed;
//AUDIOSOURCE
AudioSource audios;
public AudioClip DoorOpenSFX, DoorCloseSFX;
//VARIABLES ABRIR Y CERRAR
float startRotation;
sbyte speed = 100;
sbyte direccion;
sbyte savedDireccion;
sbyte enemySavedDireccion;
public bool locked;
public bool abriendo;
public bool abierto;
public bool cerrado;
public bool cerrando;
private BoxCollider2D doorCollider;
// Use this for initialization
void Start () {
audios = GetComponent<AudioSource>();
startRotation = transform.GetChild(0).eulerAngles.y;
doorCollider = GetComponentInChildren<DummyScripts>().GetComponent<BoxCollider2D>();
}
// Update is called once per frame
void Update () {
DoorMethod();
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
Color color = spriteHUD.color;
color.a = alphaSpeed;
spriteHUD.color = color;
buttonToPress.SetActive(true);
}
}
void OnTriggerStay2D(Collider2D other)
{
if (Input.GetKey (KeyCode.E)) {
if (!locked) {
if (cerrado) {
savedDireccion = direccion;
abriendo = true;
}
if (abierto)
cerrando = true;
}
/*if (locked){
// Play sound locked
}*/
}
if (other.gameObject.tag == "Enemy")
{
if (!locked)
{
if (cerrado)
{
savedDireccion = direccion;
abriendo = true;
}
}
}
// PLAYER DIRECTION DOOR
if (other.transform.position.x - transform.position.x > 0)
direccion = -1;
if (other.transform.position.x - transform.position.x < 0)
direccion = 1;
// ENEMY DIRECTION DOOR
/*
if (other.transform.position.x - transform.position.x > 0)
direccion = -1;
if (other.transform.position.x - transform.position.x < 0)
direccion = 1;*/
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
buttonToPress.SetActive (false);
if (abierto && other.gameObject.tag == "Enemy")
cerrando = true;
}
void DoorMethod()
{
if (!locked)
{
if (abriendo)
{
if (!audios.isPlaying)
{
audios.PlayOneShot(DoorOpenSFX, 0.4f);
}
abierto = false;
transform.GetChild(0).Rotate(Vector3.up * speed * savedDireccion * Time.deltaTime);
}
if (transform.GetChild(0).eulerAngles.y > startRotation + 90f || transform.GetChild(0).eulerAngles.y < startRotation - 90f)
{
abriendo = false;
abierto = true;
cerrado = false;
}
if (cerrando)
{
if (!audios.isPlaying)
{
audios.PlayOneShot(DoorCloseSFX, 0.4f);
}
cerrado = false;
transform.GetChild(0).Rotate(Vector3.up * speed * -savedDireccion * Time.deltaTime);
}
if (transform.GetChild(0).eulerAngles.y > startRotation - 1 && transform.GetChild(0).eulerAngles.y < startRotation + 1)
{
cerrando = false;
cerrado = true;
abierto = false;
}
if (cerrado)
{
doorCollider.enabled = true;
}
else
{
doorCollider.enabled = false;
}
}
}
}