Score Manager/Display not working

I just started coding so sorry if this is any easy fix, but I’m not able to get my score display to work in any way at all. Bellow will be the code I’m using and an image please help.

ScoreManager.cs

using UnityEngine;

public class ScoreManager : MonoBehaviour
{
    private int totalDamageDealt = 0;
    public int TotalDamageDealt => totalDamageDealt;

    public void AddDamage(int damage)
    {
        totalDamageDealt += damage;
    }
}

ScoreDisplay.cs

using UnityEngine;
using UnityEngine.UI;

public class ScoreDisplay : MonoBehaviour
{
    public Text scoreText;

    void Update()
    {
        ScoreManager scoreManager = FindObjectOfType<ScoreManager>();

        if (scoreManager != null && scoreText != null)
        {
            // Update the displayed score
            scoreText.text = "0" + scoreManager.TotalDamageDealt;
        }
        else
        {
            Debug.LogError("ScoreManager or scoreText not found.");
        }
    }
}

To explain the hierarchy better:

  • GameManager (Empty Object with GameManager script)
    -ScoreText (Canvas)
    -Panel
    -Text (with ScoreDisplay script)

Fixed the issue

1 Answer

1

I fixed this one, some setting was disabled by default and I enabled it, easy fix

Imagine sb, in few years time, having this exact problem that you had here, finding this page and reading "some settings were disabled, easy fix, lmao". this.health--;

lol, well I came on to ask a different question and saw this one was unanswered and idr what I had to enable, but i just did it trying to disable and enable everything and then it worked, and I moved on