I have two objects, one with a mesh, collider, all of that; and an empty object right above the first one that’s supposed to do nothing but show text. In the script for the first object, I want to change the textmesh of the second, but it doesn’t seem to work. This is what I’ve got so far:
public class NPCBehavior : MonoBehaviour {
public TextWriter textWriter;
public Transform target;
Start () {
textWriter = GetComponent<TextWriter> ();
}
void Update () {
//Creating text
if (Vector3.Distance (this.transform.position, target.position) < 1.8f) {
textWriter.textMesh.text = "Hey!";
}
}
I dragged the empty object with the textwriter script onto the public textwriter slot in the first object’s inspector.
The textwriter script is practically empty, it just holds a public textmesh which I drag from the standard textmesh component.
Also, the error in question is “Object reference not set to an instance of an object.”