- Home /
On click add listener not working !
Thats code for dialogue system, it has no errors but when i get to object dialogue opens but when i want to click continue to next dialogue i nothing happens, like that continue button its freezed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueSystem : MonoBehaviour {
public static DialogueSystem Instance {get;set;}
public GameObject dialoguePanel;
public string npcName;
public List<string> dialoguelines = new List<string> ();
Button continueButton;
Text dialogueText,nameText;
int dialogueIndex;
void Awake ()
{
dialoguePanel.SetActive (false);
continueButton = dialoguePanel.transform.FindChild("Continue").GetComponent<Button>();
dialogueText = dialoguePanel.transform.FindChild ("Text").GetComponent<Text> ();
nameText = dialoguePanel.transform.FindChild ("Name").GetChild (0).GetComponent <Text> ();
continueButton.onClick.AddListener (delegate {
ContinueDialogue ();
});
if (Instance != null && Instance != this) {
Destroy (gameObject);
} else
{
Instance = this;
}
}
public void AddNewDialogue(string[]lines, string npcName)
{
dialogueIndex = 0;
dialoguelines = new List<string> ();
foreach(string line in lines)
{
dialoguelines.Add (line);
}
this.npcName = npcName;
Debug.Log (dialoguelines.Count);
CreateDialogue ();
}
public void CreateDialogue ()
{
dialogueText.text = dialoguelines [dialogueIndex];
nameText.text = npcName;
dialoguePanel.SetActive (true);
}
public void ContinueDialogue()
{
if (dialogueIndex < dialoguelines.Count - 1) {
dialogueIndex++;
dialogueText.text = dialoguelines[dialogueIndex];
} else
{
dialoguePanel.SetActive (false);
}
}
}
Thats the code for NPC(object), and theres no error too.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NPC : Interactable {
public string[] dialogue;
public string name;
public override void Interact()
{
DialogueSystem.Instance.AddNewDialogue (dialogue,name);
print ("interacting with NPC");
}
}
Comment
Your answer
Follow this Question
Related Questions
Where can I learn to make a tile system? 1 Answer
Help with Input.GetAxis??? 1 Answer
My dialogue system has a strange bug 0 Answers
How to Move player by itself to a positions when talking to an NPC? 0 Answers
Advice for making a 2D Dialogue System? 2 Answers