-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnTriggerLoadLevel(3D).cs
More file actions
50 lines (43 loc) · 1.1 KB
/
OnTriggerLoadLevel(3D).cs
File metadata and controls
50 lines (43 loc) · 1.1 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class OnTriggerLoadLevel(3D) : MonoBehaviour
{
[Header("Distance")]
[SerializeField] private float _theDistance;
[Header("Action Object")]
[SerializeField] private string _actionText; //Example: [E] To the Beach
[SerializeField] private GameObject actionObject;
[Header("Load Scene")]
[SerializeField] private string _levelToLoad;
[SerializeField] private GameObject fadeOut;
private void Update()
{
_theDistance = PlayerCasting.distanceFromTarget;
}
private void OnMouseOver()
{
if (_theDistance <= 3)
{
actionObject.GetComponent<Text>().text = _actionText;
actionObject.SetActive(true);
if (Input.GetButtonDown ("Action"))
{
fadeOut.SetActive(true);
StartCoroutine(TransferScene());
}
}
}
private void OnMouseExit()
{
actionObject.SetActive(false);
}
private IEnumerator TransferScene()
{
actionObject.SetActive(false);
yield return new WaitForSeconds(2);
SceneManager.LoadScene(_levelToLoad);
}
}