generated from PurdueSIGGD/SIGGD-Unity-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExitTrigger.cs
33 lines (29 loc) · 896 Bytes
/
ExitTrigger.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
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
/** If player enters trigger, the player is moved to the next scene
*/
public class ExitTrigger : MonoBehaviour
{
private bool triggeredYet = false;
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Player" && !triggeredYet)
{
triggeredYet= true;
float T = other.GetComponentInChildren<PavelAudio>().endLevel();
if (T > 0)
{
IEnumerator coroutine = waitToLeave(T);
StartCoroutine(coroutine);
}
}
}
public IEnumerator waitToLeave(float waitTime)
{
yield return new WaitForSeconds(waitTime + 0.5f);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}