Hi, im doing a dialogue system and making a boolean that initializes as true even if its set to be false, when inside a trigger collider it should switch to true, but its true all the time regardless.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogoDaro : MonoBehaviour
{
public GameObject Daro;
public Text dialogo;
public RawImage Cartel;
public Image fondoNombre;
public Text Nombre;
public Text AvanzarDialogo;
[SerializeField] int counter = 0;
[SerializeField] string[] dialogoArray = new string[] {"Hola amigo!", "No sé si te enteraste, probablemennte si, pero...", "Ahora en un rato es empatizando!", "Y los meps no llegaron...", "Tengo una idea!", "Podrias ayudarme a buscar los proyectos mas importantes?", "Tengo que... ordenarlos...", "Despues, veni aca y dejalos todos apilados... Ya vas a ver","¿Porque seguis aca? Anda!" };
[SerializeField] bool enRango = false;
// Start is called before the first frame update
void Start()
{
enRango = false;
//initialize as false
}
// Update is called once per frame
void Update()
{
if (enRango)
{
{
if (Input.GetKeyDown(KeyCode.E) && counter <= 6)
{
counter++;
Debug.Log(counter);
dialogo.text = dialogoArray[counter];
}
}
}
if(counter >= 7)
{
AvanzarDialogo.enabled = false;
}
}
void OnTriggerEnter(Collider Daro)
{
if(Daro.transform.tag == "NPC"){
if (counter >= 7)
{
AvanzarDialogo.enabled = false;
}
else
{
AvanzarDialogo.enabled = true;
}
Cartel.enabled = true;
dialogo.enabled = true;
fondoNombre.enabled = true;
Nombre.enabled = true;
Debug.Log("entraste");
}
}
void OnTriggerStay(Collider Daro)
{
if(Daro.transform.tag == "NPC")
{
// boolean for inRange goes true
enRango = true;
}
}
void OnTriggerExit(Collider Daro)
{
if(Daro.transform.tag == "NPC")
{
Cartel.enabled = false;
dialogo.enabled = false;
fondoNombre.enabled = false;
Nombre.enabled = false;
AvanzarDialogo.enabled = false;
// All text until here
enRango = false;
}
}
}