Using C# with guiTex object

First off I’m sorry if this is something simple I tried to search for a solution but came up empty.

I’m having trouble using C# with box collider. What I want to have happen is when my capsule enters a box collider it triggers a message to display on a guiText object. I can do this in JavaScript but have been unable to get it to work in C#. I need to use C# because what I eventually want to display is being read in from a txt file. Any help would be greatly appreciated!

Below is my skeleton attempt to get any text to display in a guiText object. I can’t attach a guiText to the script. I can attach it to the collider but just get an error when the capsule enters the box collider.

Any help would be greatly appreciated!

using UnityEngine;
using System.Collections;
using System;
using System.IO;

public class MRoomCS : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}

void OnTriggerEnter(Collider collision)
{
guiText.text = “Is Working”;
}

void OnTriggerExit(Collider collision)
{
guiText.text = “”;
}

}

Why do you think reading from files is only possible in C#? The entire .Net api is available to JavaScript as well.

Regarding your code. You do not define a member variable for the gui text object. The guiText variable you are assigning to is a convenience property that tries to find a GuiText component on the current game object. (The same thing as running GetComponent(typeof(GuiText)) .) This is why you get an error in your original code, as you most likely don’t have the trigger and the GuiText component attached to the same game object.

Change your code to this:

using UnityEngine;
using System.Collections;
using System;
using System.IO;


public class MRoomCS : MonoBehaviour {

  public GuiText message;

  void OnTriggerEnter(Collider collision)
  {
    message.text = "Is Working";
  }

  void OnTriggerExit(Collider collision)
  {
    message.text = "";
  }

}

Thanks you very much that worked perfectly. As to your comment I didn’t know that about the .net framework. I will look into that.

Thanks again

Nate