65 lines
1.5 KiB
C#
65 lines
1.5 KiB
C#
using Scampz.GameJam.Assets.Scripts.Audio;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Scampz.GameJam
|
|
{
|
|
public class LoadScene : MonoBehaviour
|
|
{
|
|
private bool _loaded = false;
|
|
[SerializeField]
|
|
private string _scene;
|
|
[SerializeField]
|
|
private bool _promptToEnter;
|
|
[SerializeField]
|
|
private TextMeshProUGUI _promptText;
|
|
|
|
private InputAction confirmAction;
|
|
|
|
void Start()
|
|
{
|
|
confirmAction = new InputAction("confirm", binding: "<Keyboard>/x");
|
|
confirmAction.AddBinding("<GamePad>/buttonSouth");
|
|
confirmAction.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
confirmAction.Disable();
|
|
}
|
|
|
|
void OnTriggerEnter(Collider collider)
|
|
{
|
|
if (!_loaded && collider.CompareTag("Player"))
|
|
{
|
|
if (_promptToEnter)
|
|
_promptText.enabled = true;
|
|
|
|
if (!_promptToEnter)
|
|
LoadNextLevel();
|
|
}
|
|
}
|
|
|
|
private void OnTriggerStay(Collider collider)
|
|
{
|
|
if (!_loaded && collider.CompareTag("Player") && _promptText != null && _promptText.enabled && confirmAction.IsPressed())
|
|
LoadNextLevel();
|
|
}
|
|
|
|
private void OnTriggerExit(Collider collider)
|
|
{
|
|
if (_promptToEnter && collider.CompareTag("Player"))
|
|
_promptText.enabled = false;
|
|
}
|
|
|
|
private void LoadNextLevel()
|
|
{
|
|
_loaded = true;
|
|
SFXManager.Instance.PlaySoundEffect(SoundEffectName.Ok);
|
|
GameManager.Instance.LoadScene(_scene, LoadSceneMode.Single);
|
|
}
|
|
}
|
|
}
|