52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace Scampz.GameJam
|
|
{
|
|
public class PromptDialogue : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private DialogueTrigger _dialogueTrigger;
|
|
|
|
private bool _isWithinRange = false;
|
|
|
|
private InputAction confirmAction;
|
|
|
|
void Start()
|
|
{
|
|
confirmAction = new InputAction("confirm", binding: "<Keyboard>/x");
|
|
confirmAction.AddBinding("<GamePad>/buttonSouth");
|
|
confirmAction.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
confirmAction.Disable();
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
_isWithinRange = true;
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
_isWithinRange = false;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_isWithinRange && confirmAction.triggered && !DialogueManager.Instance.IsTalking)
|
|
{
|
|
var player = GameObject.FindGameObjectWithTag("Player");
|
|
var cc = player.GetComponent<CharacterController>();
|
|
cc.enabled = false;
|
|
_dialogueTrigger.TriggerDialogue();
|
|
cc.enabled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|