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. Dismiss Notice

Question NullReferenceException: Object reference not set to an instance of an object CoinManager.Update () (

Discussion in 'Scripting' started by Spielagent005, Sep 24, 2023.

  1. Spielagent005

    Spielagent005

    Joined:
    Sep 24, 2023
    Posts:
    1
    What is wrong with this Code? How can I use TMP_Text i do not understand this?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class CoinManager : MonoBehaviour
    7. {
    8.     public int geld;
    9.     public Text money;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.  
    14.     }
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         money.text = geld.ToString();
    19.     }
    20.     public void AddMoney()
    21.     {
    22.         geld++;
    23.     }
    24. }
    25.  
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563