literally half of the game
This commit is contained in:
parent
1590b5faa6
commit
b842289076
77 changed files with 11904 additions and 72 deletions
60
Assets/Scripts/Entity/PlayerTalkRange.cs
Normal file
60
Assets/Scripts/Entity/PlayerTalkRange.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerTalkRange : MonoBehaviour
|
||||
{
|
||||
private List<NPC> npcsInRange = new(); //also indicate the npc you're closest to
|
||||
[Header("UI")]
|
||||
[SerializeField] private Transform talkPopupUI;
|
||||
[SerializeField] private Vector3 uiOffset;
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.TryGetComponent(out NPC isNPC) && !npcsInRange.Contains(isNPC)) //placeholder key lol
|
||||
{
|
||||
npcsInRange.Add(isNPC);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if (other.TryGetComponent(out NPC isNPC) && npcsInRange.Contains(isNPC)) //placeholder key lol
|
||||
{
|
||||
npcsInRange.Remove(isNPC);
|
||||
if (npcsInRange.Count == 0)
|
||||
{
|
||||
talkPopupUI.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (npcsInRange.Count > 0)
|
||||
{
|
||||
NPC closestNPC = null;
|
||||
foreach (NPC npc in npcsInRange)
|
||||
{
|
||||
if (!closestNPC || Vector3.Distance(closestNPC.transform.position, transform.position) >
|
||||
Vector3.Distance(npc.transform.position, transform.position))
|
||||
{
|
||||
closestNPC = npc;
|
||||
}
|
||||
}
|
||||
|
||||
if (closestNPC)
|
||||
{
|
||||
if (!talkPopupUI.gameObject.activeSelf)
|
||||
{
|
||||
talkPopupUI.gameObject.SetActive(true);
|
||||
}
|
||||
talkPopupUI.position = closestNPC.transform.position + uiOffset;
|
||||
}
|
||||
|
||||
if (DialogueManager.instance.currentDialogueScript == null && Input.GetKeyDown(KeyCode.E))
|
||||
{
|
||||
closestNPC.StartDialogue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue