-1

I'm new to Unity and trying to learn the basics. I have a text box on a canvas that I'm trying to manipulate, right now by changing it from "Name" to "Test" at game start.

using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;

public class TextData : MonoBehaviour
{

    TextMeshProUGUI textmeshpro;
    
    void start()
    {
        textmeshpro = GetComponent<TextMeshProUGUI>();
        textmeshpro.text = "Test";
    }

}

This gives the error: NullReferenceException: Object reference not set to an instance of an object Load.Start () (at Assets/Load.cs:18)

So it's telling me textmeshpro is set to null (which it shouldn't be, I have text in the inspector), but since I can't access the text field without GetComponent, I have no idea how I can fix this error.

Raddy
  • 39
  • 2
  • 6

1 Answers1

0

I didn't read the error correctly, it was referring to a line of code in another script.

Raddy
  • 39
  • 2
  • 6