I’m making a 2D RPG and I’m working on the Dialogue system right now, I have an NPC and it has 2, 2D Box Colliders. One is a “is trigger” so the player can go through and activate the system, the other is a box collider so the player can’t go through the NPC. Whenever the player enters the “is trigger area” it doesn’t notice the player so it can’t activate the dialogue system. I have 2 scripts a DialogManager and a DialogActivator. Not sure why it’s doing that if anyone can help?
DialogManager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogManager : MonoBehaviour
{
public Text dialogText;
public Text nameText;
public GameObject dialogBox;
public GameObject nameBox;
public string[ ] dialogLines;
public int currentLine;
public static DialogManager instance;
private bool justStarted;
// Start is called before the first frame update
void Start()
{
instance = this;
//dialogText.text = dialogLines[currentLine];
}
// Update is called once per frame
void Update()
{
if(dialogBox.activeInHierarchy)
{
if(Input.GetButtonUp("Fire1"))
{
if (!justStarted)
{
currentLine++;
if (currentLine >= dialogLines.Length)
{
dialogBox.SetActive(false);
}
else
{
dialogText.text = dialogLines[currentLine];
}
} else
{
justStarted = false;
}
}
}
}
public void ShowDialog(string[ ] newLines)
{
dialogLines = newLines;
currentLine = 0;
dialogText.text = dialogLines[0];
dialogBox.SetActive(true);
justStarted = true;
}
}
DialogActivator:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogActivator : MonoBehaviour
{
public string[ ] lines;
private bool canActivate;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(canActivate && Input.GetButtonDown("Fire1") && !DialogManager.instance.dialogBox.activeInHierarchy)
{
DialogManager.instance.ShowDialog(lines);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")
{
canActivate = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Player")
{
canActivate = false;
}
}
}
