My script has been working fine for the past few weeks but suddenly I get a console error when I run it and the message I want to display on the screen isn’t displayed.
Here is my script:
using UnityEngine;
using System.Collections;
public class CutSceneLight1 : MonoBehaviour {
public int wait;
public GUIStyle text;
string message = " ";
//GUI Box
void OnGUI() {
GUI.Label((new Rect(600,400,200,200)),message ,text);
}
//Displaying text
IEnumerator OnTriggerEnter(Collider otherObjective){
if (otherObjective.tag == "Player") {
message = "Message here";
StartCoroutine(message);
yield return new WaitForSeconds(wait);
message = "Another message here";
What I want to happen is for the player to cross the collider which is set as trigger and then the messages play.
Please help me I need to fix this as soon as possible.
Thanks!
Here is a small textoutputmanager i wrote for my current project.
it will show for 3 seconds a specific message and will disable after that.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextOutPutManager : MonoBehaviour {
//panel ggf.
public GameObject textPanel;
//text field output
public Text MessageOutput;
//string message
public string message = "";//this is the message to show
//string incoming message
public string incomingMessage = "this is the message send from outside";
//bool showtext
public bool showtext = false;
// Use this for initialization
void Start ()
{
textPanel.SetActive(false);
}
// Update is called once per frame
void Update ()
{
if(showtext)
{
StartCoroutine("Timer");
}
else
{
StopCoroutine("Timer");
}
}
private IEnumerator Timer()
{
message = incomingMessage;
MessageOutput.text = message;
textPanel.SetActive(true);
yield return new WaitForSeconds (3);
message = "";
MessageOutput.text = message;
textPanel.SetActive(false);
showtext = false;
}
}
Not entirely sure what you’re trying to accomplish with the messages, but you are trying to call a string as a function? (“message” is a string).
Also, OnTriggerEnter should be a void. I imagine you want to apply StartCoroutine(displayMessage(message)); to an IEnumerator displayMessage(string msg); function?