36 lines
895 B
C#
36 lines
895 B
C#
using UnityEngine;
|
|
|
|
public class NPCDialogueTrigger : MonoBehaviour
|
|
{
|
|
public DialogueAsset dialogue;
|
|
public string interactKey = "e";
|
|
public float interactRange = 2.2f;
|
|
|
|
Transform _player;
|
|
|
|
void Start()
|
|
{
|
|
var p = GameObject.FindGameObjectWithTag("Player");
|
|
_player = p ? p.transform : null;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (DialogueManager.Instance && DialogueManager.Instance.IsRunning) return;
|
|
if (_player == null) return;
|
|
|
|
if (Vector3.Distance(transform.position, _player.position) <= interactRange)
|
|
{
|
|
if (Input.GetKeyDown(interactKey.ToLower()))
|
|
{
|
|
DialogueManager.Instance.StartDialogue(dialogue);
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnDrawGizmosSelected()
|
|
{
|
|
Gizmos.color = Color.yellow;
|
|
Gizmos.DrawWireSphere(transform.position, interactRange);
|
|
}
|
|
} |