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
GameManagerscript)
-ScoreText (Canvas)
-Panel
-Text (withScoreDisplayscript)

Fixed the issue
– england61300