- Home /
Adding C# Text Crawl to Dialogue Script?
I'm currently making a 2D game and really want a text crawl, like in Undertale. I already have my dialogue script but have no clue how to begin text crawling. . . My scripts use the text that is in a public string with several lines so I don't have to write a whole new script for each character and investigatable object. . . Is it possible to add text crawl to it without having to write a new script per dialogue box? I have my two dialogue scripts here, the first being my dialogue manager script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialougeManager : MonoBehaviour {
public GameObject dBox;
public Text dText;
public bool dialogActive;
public string[] dialogLines;
public int currentLine;
private PlayerController thePlayer;
// Use this for initialization
void Start () {
thePlayer = FindObjectOfType<PlayerController> ();
}
// Update is called once per frame
void Update () {
if (dialogActive && Input.GetKeyDown (KeyCode.Z))
{
//dBox.SetActive (false);
//dialogActive = false;
currentLine++;
}
if (currentLine >= dialogLines.Length) {
dBox.SetActive (false);
dialogActive = false;
currentLine = 0;
thePlayer.canMove = true;
}
dText.text = dialogLines [currentLine];
}
public void ShowBox(string dialogue)
{
dialogActive = true;
dBox.SetActive (true);
dText.text = dialogue;
}
public void ShowDialogue()
{
dialogActive = true;
dBox.SetActive (true);
thePlayer.canMove = false;
}
}
The second is my dialogue holder script : using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DialougeHolder : MonoBehaviour {
public string dialogue;
private DialougeManager dMan;
public string[] dialogueLines;
// Use this for initialization
void Start () {
dMan = FindObjectOfType<DialougeManager> ();
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay2D(Collider2D other)
{
if (other.gameObject.name == "David") {
if (Input.GetKeyUp (KeyCode.Z)) {
//dMan.ShowBox (dialogue);
if (!dMan.dialogActive) {
dMan.dialogLines = dialogueLines;
dMan.currentLine = 0;
dMan.ShowDialogue ();
}
}
}
}
}
Thank you so much to anyone that can give me any input!!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
RPGStatSystem tutorial problem with clases visibility? 1 Answer
Add audio. 1 Answer