Dialogue start button
I'm working on a 2D top-down game and I made a dialogue system using a tutorial. I'm still fairly new to scripting.
The problem is that tutorial was starting the dialogue by placing a button on the canvas and activating the conversation by pressing it.
Is there a way that I can switch that task to a keyboard button, make the keyboard button access that script instead?
Also I'm trying to change the name colors in the dialogue for each specific person, but it isn't working for some reason.
This is the code I'm using:
using UnityEngine.UI;
using UnityEngine;
using System.Collections;
using TMPro;
public class DialogueManager : MonoBehaviour
{
public TextMeshProUGUI speakerName, dialogue, navButtonText;
public Image speakerSprite;
private int currentIndex;
private Conversation currentconvo;
private static DialogueManager instance;
private Animator anim;
private Coroutine typing;
private string sName;
private void Awake()
{
if(instance == null)
{
instance = this;
anim = GetComponent<Animator>();
}
else
{
Destroy(gameObject);
}
}
public static void StartConversation(Conversation convo)
{
instance.anim.SetBool("isOpen", true);
instance.currentIndex = 0;
instance.currentconvo = convo;
instance.speakerName.text = "";
instance.dialogue.text = "";
instance.navButtonText.text = "";
instance.ReadNext();
}
public void ReadNext()
{
if(currentIndex > currentconvo.GetLength())
{
instance.anim.SetBool("isOpen", false);
return;
}
sName = currentconvo.GetLineByIndex(currentIndex).speaker.GetName();
speakerName.text = sName;
if(typing == null)
{
typing = instance.StartCoroutine(TypeText(currentconvo.GetLineByIndex(currentIndex).dialogue));
}
else
{
instance.StopCoroutine(typing);
typing = null;
typing = instance.StartCoroutine(TypeText(currentconvo.GetLineByIndex(currentIndex).dialogue));
}
speakerSprite.sprite = currentconvo.GetLineByIndex(currentIndex).speaker.GetSprite();
currentIndex++;
}
private IEnumerator TypeText(string text)
{
dialogue.text = "";
bool complete = false;
int index = 0;
while (!complete)
{
dialogue.text += text[index];
index++;
yield return new WaitForSeconds(0.04f);
if (index == text.Length)
complete = true;
}
typing = null;
}
public void pickSpeakerName(string PickSpeakerNameColor)
{
Debug.Log(name);
if(name == "Nyx")
{
speakerName.color = Color.blue;
}
else if(name == "Creator")
{
speakerName.color = Color.cyan;
}
else
{
speakerName.color = Color.white;
}
}
}
Your answer

Follow this Question
Related Questions
I need Function to be in other script 1 Answer
Physics2D.OverlapCircle working in Unity but not in build 0 Answers
Get color from ColorPicker and apply it randomly on GameObject 0 Answers
How can I make a float decrease when touched by a cube? 0 Answers
How do I get an audio clip to play at a specific time? 0 Answers