Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Object reference not set to an instance of an object

Discussion in 'Scripting' started by The_Legendary_Kiwi, Jun 4, 2022.

  1. The_Legendary_Kiwi

    The_Legendary_Kiwi

    Joined:
    Feb 12, 2022
    Posts:
    2
    I'm very new to unity and don't understand why I get this error, in the unity editor I have an gameobject which contains this script as a component, I attached the UI-text to the script in the component but it just shows the error and the text doesn't change.

    Code (CSharp):
    1. using UnityEngine.UI;
    2.  
    3. public class GlobalScore : MonoBehaviour
    4. {
    5.  
    6.     public GameObject ScoreDisplay;
    7.     private void Update()
    8.     {
    9.         ScoreDisplay.GetComponent<Text>().text = "SCORE: ";
    10.     }
    11. }
    Its probably an easy fix but any help is appreciated
     
  2. lordconstant

    lordconstant

    Joined:
    Jul 4, 2013
    Posts:
    389
    The_Legendary_Kiwi likes this.
  3. The_Legendary_Kiwi

    The_Legendary_Kiwi

    Joined:
    Feb 12, 2022
    Posts:
    2