Question by
replay55 · Nov 30, 2015 at 06:23 PM ·
errorguitextcompilerobject reference
Compiler Error CS0120, GUIText
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class triggerZone : MonoBehaviour {
public AudioClip lockedsound;
public Text text;
public static bool inside = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public 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"));
}
}
else
{
AudioSource.PlayClipAtPoint (lockedsound, transform.position);
Col.gameObject.SendMessage("HUDon");
TextHints.SendMessage("ShowHint", "This Door is locked, I need to power it!", UnityEngine.SendMessageOptions);
}
}
}
}
As you can see, this script sends a message to the Object (I think? I'm new to this. .3.) ShowHints, however, apparently, ShowHints is nonstatic, even though I made it static..?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextHints : MonoBehaviour {
public static 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!";
}
}
static void ShowHint(string message){
text.text = message;
if(!text.enabled){
text.enabled = true;
}
}
}
Did I not make it static? How can I set up an object reference? Here is the full error:
Assets/scripts/triggerZone.cs(31,43): error CS0120: An object reference is required to access non-static member `UnityEngine.Component.SendMessage(string, object, UnityEngine.SendMessageOptions)'
Comment