0

I get that this question may already have an answer, but i was'nt able to find a solution anywhere. I am getting a NullRefrenceExeption, when i try to update the text of my UI-Element on line 18, and i have no idea why.

I simply want the text to update when a condition is met. Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CameraFollow : MonoBehaviour
{
    private int score;

    public Text ScoreText;
    public Transform target;

    void LateUpdate()
    {
        score = 0;
        if (target.position.y > transform.position.y)
        { 
            Vector3 newPos = new Vector3(transform.position.x, target.position.y, transform.position.z);
            transform.position = newPos;
            score += 1;
            ScoreText.text = "hello" + score.ToString();
        }
    }
}

Hope you can help

George
  • 4,736
  • 2
  • 32
  • 47
Oliver Olsen
  • 70
  • 2
  • 8

0 Answers0