Hello everyone,
I am working on a scrolling text program using snippets provided by user Broxxar, and it was working splendidly in the Unity game window until I used “Build & Run”, now it won’t work as an executable or in the Unity game window.
Have a look at this code:
using UnityEngine;
using System.Collections;
public class DialogueScript : MonoBehaviour {
public GUIStyle dialogueStyle;
float dialogueWidth;
float dialogueHeight;
public string dialogue;
public string typingDialogue;
public bool dialogueActive;
public bool typing;
float bufferSpace;
public Texture2D dialogueBackgroundImage;
void Start () {
dialogue = "Hello and welcome to the wonderful world of avatar selection!";
}
void Update () {
//This adjusts the dialogue box to always take up the bottom 40% of the screen.
dialogueWidth = (Screen.width);
dialogueHeight = (0.4f * Screen.height);
if(Input.GetKeyDown (KeyCode.A)){
dialogueActive = !dialogueActive;
}
bufferSpace = (0.1f * dialogueHeight);
}
void OnGUI () {
//This section controls the dialogue window.
if (dialogueActive) {
//This will be the size of the dialogue window.
Rect dialogueBackground = new Rect(
0,
(Screen.height) * 0.6f,
dialogueWidth,
dialogueHeight);
//Draw the dialogue box.
GUI.DrawTexture (dialogueBackground, dialogueBackgroundImage);
//Start of Dialogue Box.
GUILayout.BeginArea (dialogueBackground);
GUILayout.Space (bufferSpace);
GUILayout.BeginHorizontal ();
GUILayout.Space (bufferSpace);
Type (dialogue);
GUILayout.Label (typingDialogue, dialogueStyle);
GUILayout.Space (bufferSpace);
GUILayout.EndHorizontal ();
GUILayout.EndArea ();
}
}
public bool Type (string dialogue) {
if (typing)
return false;
StartCoroutine(TypeDialogue(dialogue));
return true;
}
//This section scrolls the dialogue text like an old-fashioned RPG.
IEnumerator TypeDialogue (string typeDialogue) {
typing = true;
for (int i = 0; i <= typeDialogue.Length; i++) {
typingDialogue = typeDialogue.Substring(0, i);
yield return new WaitForSeconds (0.05f);
}
typing = false;
}
}
Until I hit “Build & Run”, as long as dialogueActive is true (which it shows in the inspector as true) the coroutine will begin to type the string dialogue and save it as the string typingDialogue. This is happening, as I can see the typing occur in the inspector.
Additionally, the dialogueStyle GUIStyle seems to be intact in the inspector and my dialogueBackgroundImage is also present, I even had a Debug.Log assure me this was the case.
However, the menu is now completely invisible and I can’t see typing on the screen anymore.
Why is this script suddenly not working for me after hitting Build & Run?
Thank you in advance for any help!