Hi guys. So I’m having this issue where the dialogue in the dialogue panel is working but the dialogue panel (Unity UI Panel) itself isn’t working. It’s showing a transparent background and I’ve tried replacing the dialogue panel, changing the color, etc, but nothing has been working. Dialogue is a new subject for me so any advice is much appreciated (screenshots for reference below with the code to control the dialogue panel).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Guide_Dialogue : MonoBehaviour
{
public GameObject dialoguePanel;
public TextMeshProUGUI dialogueText;
public string[] dialogue;
private int index;
public GameObject contButton;
public float wordSpeed;
public bool playerIsClose;
public bool isTalking = false;
public bool buttonActive = false;
private bool cooldown = false;
// happens when the game starts
void Start()
{
}
// Update is called once per frame
void Update()
{
// seeing if player is using inspect button while in range of guide
if(Input.GetKeyDown(KeyCode.E) && playerIsClose)
{
// clears dialogue box and resets NPC
if (dialoguePanel.activeInHierarchy)
{
//zeroText();
}
else
{
dialoguePanel.SetActive(true);
isTalking = true;
PlayerMovement.moveSpeed = 0f;
StartCoroutine(Typing());
}
}
if(Input.GetKeyDown(KeyCode.E) && isTalking && buttonActive)
{
if (cooldown == false)
{
StopCoroutine(Typing());
NextLine();
Invoke("ResetCooldown", 1.5f);
cooldown = true;
}
}
// once done, continue button becomes active
if (dialogueText.text == dialogue[index])
{
contButton.SetActive(true);
buttonActive = true;
}
}
void ResetCooldown()
{
cooldown = false;
}
// clears text box and resets index to 0 so it starts from the first line again [Can change so it doesn't set index to 0]
public void zeroText()
{
dialogueText.text = "";
PlayerMovement.moveSpeed = 5f;
isTalking = false;
index = 0;
buttonActive = false;
dialoguePanel.SetActive(false);
}
// displays letters one at a time according to wordSpeed
IEnumerator Typing()
{
foreach(char letter in dialogue[index].ToCharArray())
{
dialogueText.text += letter;
yield return new WaitForSeconds(wordSpeed);
}
}
// moves to the next line if there is a next line automatically [Can be changed to stop at certain points for cutscenes]
public void NextLine()
{
contButton.SetActive(false);
buttonActive = false;
if(index < dialogue.Length - 1)
{
index++;
dialogueText.text = "";
StartCoroutine(Typing());
}
else
{
zeroText();
}
}
// if player is in box collider, they can speak to Guide
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
playerIsClose = true;
}
}
// if player leaves box collider, dialogue is stopped [or suspended based on how you change zeroText]
private void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
playerIsClose = false;
zeroText();
}
}
}