Error 0029
I am receiving the Error 0029 on my Boolean 'inside', because I'm apparently converting it into a string in my code. What am I doing wrong?
Full Error: Cannot convert type 'string' to 'bool
Code: using UnityEngine; using System.Collections;
public class triggerZone : MonoBehaviour {
public AudioClip lockedsound;
public Light doorlight;
public GUIText texthint1;
public static bool inside = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider Col){
if (Col.gameObject.tag = "Player") {
inside = (bool) true;
if (inventory.charge == 4) {
transform.FindChild ("door").SendMessage ("DoorCheck");
if (GameObject.Find ("chargeHUDGUI")) {
Destroy (GameObject.Find ("chargeHUDGUI"));
doorlight.color = Color.green;
}
} else if(inventory.charge > 0 && inventory.charge < 4){
// TextHints.SendMessage("ShowHint" , "I think it needs more power!", UnityEngine.SendMessageOptions);
} else {
AudioSource.PlayClipAtPoint (lockedsound, transform.position);
Col.gameObject.SendMessage("HUDon");
// TextHints.SendMessage("ShowHint" , "This Door is locked, I need to power it!", UnityEngine.SendMessageOptions);
}
}
Comment
Yes, it's on line 22. here's my new code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextHints : $$anonymous$$onoBehaviour {
Text text;
public float timer = 0.0f;
// Use this for initialization
void Start () {
text = GetComponent<Text>();
}
// Update is called once per frame
void Update () {
if (text.enabled) {
timer += Time.deltaTime;
}
if (timer >= 4) {
text.enabled = false;
timer = 0.0f;
}
if (triggerZone.inside == true && inventory.charge < 5) {
text = ("Not Enough energy, the blasted pixies have stolen it!");
}
}
void ShowHint(string message){
text.text = message;
if(!text.enabled){
text.enabled = true;
}
}
}
And now it says cannot convert string to unityengineui.text. I may have messed up.
Answer by Landern · Oct 29, 2015 at 05:20 PM
Text is of type Text, to set the text you need to use the property/field called text as below, also you can remove the paratheisis.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextHints : MonoBehaviour {
Text text;
public float timer = 0.0f;
// Use this for initialization
void Start () {
text = GetComponent<Text>();
}
// Update is called once per frame
void Update () {
if (text.enabled) {
timer += Time.deltaTime;
}
if (timer >= 4) {
text.enabled = false;
timer = 0.0f;
}
if (triggerZone.inside == true && inventory.charge < 5) {
text.text = "Not Enough energy, the blasted pixies have stolen it!";
}
}
void ShowHint(string message){
text.text = message;
if(!text.enabled){
text.enabled = true;
}
}
}
Your answer
