forked from UnityTutorialsHD/Unity-Tutorial-Assets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowQuest2.cs
40 lines (33 loc) · 926 Bytes
/
ShowQuest2.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShowQuest2 : MonoBehaviour {
public GameObject questUI;
public GameObject showQuest;
bool entered = false;
bool alreadyPlayed = false;
public AudioClip sound;
private AudioSource audio;
void Start () {
audio = GetComponent<AudioSource>();
showQuest.SetActive(false);
questUI.SetActive(false);
}
void OnTriggerEnter (Collider other) {
if (other.tag == "Player" && !alreadyPlayed && !entered)
{
questUI.SetActive(true);
showQuest.SetActive(true);
audio.PlayOneShot(sound, 5);
alreadyPlayed = true;
entered = true;
}
}
void OnTriggerExit(Collider other)
{
if(other.tag == "Player")
{
Destroy(showQuest);
}
}
}