Hello peoples. I’ve run into a snafu. I’ve only very recently begun scripting with the new UI in 4.6 and I’m confused by the text. I am attempting to change the UI text when the first person controller enters a collision zone. As it stand right now, the collision triggers (verified by debug log message) but the UI text does not change. I have a UI canvas with a text object attached to it. I have this script attached to it in order to make a global text variable to be edited by other scripts. using UnityEngine; using UnityEngine.UI; using System.Collections;
- usingUnityEngine;
- usingUnityEngine.UI;
- usingSystem.Collections;
- publicclass TEXTMAKER :MonoBehaviour{
- publicTextGametext;
- voidStart(){
- Gametext=GetComponent();
- }
- }
In addition, I have a second script attached to the collider that is supposed to change the UI text when triggered:
- usingUnityEngine;
- usingUnityEngine.UI;
- usingSystem.Collections;
- publicclassTriggertextchange:MonoBehaviour
- {
- publicTextGametext;
- voidOnTriggerEnter(Collider other)
- {
- Debug.Log(“TRIGGER!”);
- Gametext= gameObject.GetComponent();
- Gametext.text=“MAXIMUM TRIGGER.”;
- }
- }
When the trigger occurs, this error message pops up in debug: NullReferenceException: Object reference not set to an instance of an object Triggertextchange.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Standard Assets/Character Controllers/Sources/Scripts/Triggertextchange.cs:13)
I am comfortable with C#, but I just can’t wrap my head around this / am probably very dumb. Any help you wonderful people can provide would be greatly appreciated.
