- Home /
Please help with GUItext
So im reading this book Unity 3.x Development Essentials. And im stuck. Right now im working on GUIText. And im trying to change it. When i come to the closed door the message shows up "Damn it! It's locked.. Maybe that generator needs power"
and after when i pick up first power cell and come back to the door it should show "This door won't budge..guess it needs fully charging- maybe more power cells will help..."
I checked my script many times and could not find anything. Plz help thanks.
using UnityEngine;
using System.Collections;
public class TriggerZone : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public AudioClip lockedSound;
public GUIText textHints;
public Light doorLight;
void OnTriggerEnter(Collider col){
if(col.gameObject.tag=="Player"){
if(Inventory.charge==4){
transform.FindChild("door").SendMessage("DoorCheck");
if(GameObject.Find("PowerGUI")){
Destroy (GameObject.Find("PowerGUI"));
doorLight.color=Color.green;
}
else if(Inventory.charge > 0 && Inventory.charge < 4){
textHints.SendMessage("ShowHint",
"This door won't budge..guess it needs fully charging- maybe more power cells will help...");
transform.FindChild("door").audio.PlayOneShot(lockedSound);
}
}else{
transform.FindChild("door").audio.PlayOneShot(lockedSound);
col.gameObject.SendMessage("HUDon");
textHints.SendMessage("ShowHint", "Damn it! It's locked.. Maybe that generator needs power");
}
}
}
}
Answer by Loius · Aug 15, 2012 at 11:01 PM
Your GUIText object (textHints) needs a script on it (and it looks like that thing should be a globally accessible variable, not a local var on a door?). The script must have a function named ShowHint that takes a string as the parameter. The ShowHint function is what you need to check.
You could add Debug.Log("Whatever") statements to be sure the door is actually recognizing that it's hit the player.
Is the book teaching you to use all these SendMessage calls? Blech. SendMessage is slow and -really- hard to debug. I hope it's not telling you to use it all over the place.
Here is the script for textHints
using UnityEngine; using System.Collections;
public class textHints : $$anonymous$$onoBehaviour { float timer=0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(guiText.enabled){
timer+=Time.deltaTime;
if(timer>=4){
guiText.enabled=false;
timer=0.0f;
}
}
}
void ShowHint(string message){
guiText.text= message; if(!guiText.enabled){guiText.enabled=true;} } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613075728im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
C# 2d Instantiate GUIText and lock it to position on map, not to follow camera. 1 Answer
GUItext works 1 of 3 situations? 0 Answers
Draw GuiText on 2d tile sprite Like 2048 game 0 Answers
Display GUI Text 1 Answer
cannot drag script to player.Guitext error,cannot drag player script to the player in hierarchy 2 Answers