I'm writing a conversation section for my game, but I'm having trouble implementing a click to continue. I may put everything in xml, but for now I just want to see what's up with this part. I'm not sure what the bug is. Something to do with update(). I'm not getting the next play for some reason. Sometimes the counter does go up though.
Thanks for reading :)
scene control
public class scene_engine : MonoBehaviour {
private string currentScene;
private int currentStep;
private bool playing;
private bool sceneEnded;
public GameObject gameEngine;
public GameObject textEngine;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (playing) {
if(Input.GetKeyUp(KeyCode.Space))
{
// clear the current text in text engine
textEngine.GetComponent<text_engine>().clear ();
// clear the current co-routine
currentStep++;
play_scene();
Debug.Log ("STEP: " + currentStep);
}
}
}
public void set_playing(bool playSet)
{
playing = playSet;
}
public bool return_playing()
{
return playing;
}
public void run_scene(string sceneSet)
{
currentScene = sceneSet;
currentStep = 0;
playing = true;
play_scene();
}
public void play_scene()
{
switch (currentScene) {
case "mt arlon intro":
// Intro scene within mt arlon
switch(currentStep)
{
case 0:
textEngine.GetComponent<text_engine>().write("Riu", "We haven't got much farther to go now.");
currentStep++;
break;
case 1:
textEngine.GetComponent<text_engine>().write("Rin", "How are you holding up Tweet?.");
break;
}
// End mt arlon intro clip
break;
// End cutscene select
}
}
}
text engine
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class text_engine : MonoBehaviour {
public GameObject name_bottom;
public GameObject speech_bottom;
public GameObject gameEngine;
public GameObject sceneEngine;
private Coroutine textID;
private string character;
private string message;
private float letterPause;
private bool writing;
// Use this for initialization
void Start () {
letterPause = 0.1f;
writing = false;
}
// Update is called once per frame
void Update () {
}
public void clear()
{
name_bottom.GetComponent<Text>().text = "";
speech_bottom.GetComponent<Text>().text = "";
StopCoroutine(textID);
}
public void write(string nameSet, string messageSet)
{
character = nameSet;
message = messageSet;
writing = true;
textID = StartCoroutine (write_text());
}
IEnumerator write_text()
{
foreach (char letter in message.ToCharArray()) {
name_bottom.GetComponent<Text>().text = character;
speech_bottom.GetComponent<Text>().text += letter;
yield return new WaitForSeconds(letterPause);
}
if (gameEngine.GetComponent<game_engine> ().return_pause () && !sceneEngine.GetComponent<scene_engine> ().return_playing ()) {
gameEngine.GetComponent<game_engine> ().set_pause (false);
}
}
public bool return_writing()
{
return writing;
}
}