Please be nice, I´m new with Unity and programming… I´m working on this simple game, I want the score to increase by 1 or decrease by 1 depending on the selection of the player. Is kind of a test game, where you have to choose the correct answer. I have each answer on independent box colliders, but I can´t get the score updated if I click the correct or wrong answer… I made a script for the canva of UI, and a script for the text (wich is the same as the script for Game Manager), but nothing happens… What am I doing wrong? any suggestions?
Thank you in advance…
Here are the scripts:
GameManager
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public int score = 0;
public Text scoreText; // Variable para el objeto de texto
void Start()
{
// Inicializa el texto del puntaje
UpdateScoreText();
}
public void IncreaseScore()
{
score++;
UpdateScoreText();
}
public void DecreaseScore()
{
score--;
UpdateScoreText();
}
void UpdateScoreText()
{
if (scoreText != null)
{
scoreText.text = "Score: " + score;
}
}
}
UI Manager:
using UnityEngine;
using UnityEngine.UI;
public class UIManager : MonoBehaviour
{
public Text scoreText; // Referencia al objeto de texto que mostrará el puntaje
private GameManager gameManager; // Referencia al GameManager
void Start()
{
// Encuentra el GameManager en la escena
gameManager = FindObjectOfType<GameManager>();
if (gameManager == null)
{
Debug.LogError("UIManager: No se encontró el objeto GameManager en la escena.");
}
}
void Update()
{
// Actualiza el texto del puntaje en la pantalla con el valor del GameManager
if (gameManager != null && scoreText != null)
{
scoreText.text = "Score: " + gameManager.score;
}
}
}
Thank you!
Luis.