-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnlockedDoor.cs
59 lines (50 loc) · 1.68 KB
/
UnlockedDoor.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
[RequireComponent(typeof(AudioSource))]
public class UnlockedDoor : InteractObject {
public string sceneToLoad;
private AudioSource sound;
private bool overlap = false;
// Use this for initialization
void Start () {
sound = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Interact") &&
((!GameManager.isEyeClosed && !interactWhenEyesClosed) || interactWhenEyesClosed) &&
!GameManager.isDialoguePlaying) {
if (overlap) {
StartCoroutine(ChangeLevel());
}
}
}
private void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
overlap = true;
//Debug.Log("overlapping is " + overlapping);
}
}
private void OnTriggerExit(Collider other) {
if (other.tag == "Player") {
overlap = false;
//Debug.Log("overlapping is " + overlapping);
}
}
IEnumerator ChangeLevel() {
overlap = false;
DontDestroyOnLoad(gameObject);
sound.Play();
GameManager.instance.setGamePaused(true);
GameManager.instance.toggleFade();
yield return new WaitForSeconds(1);
SceneManager.LoadScene(sceneToLoad);
GameManager.instance.toggleFade();
yield return new WaitForSeconds(1);
GameManager.instance.setGamePaused(false);
Debug.Log("Transition to scene complete");
Destroy(gameObject);
}
}