I’m still a complete scrub when it comes to all of this and I am having an issue with my UI once the game has been built. I’m building a Pong clone which is designed to increment a score based on which goal the game ball enters and it works fine in the editor. But as soon as I build the game and test it the UI will not update.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Score : MonoBehaviour {
private int CurrentScore;
private int CurrentAIScore;
public Text PlayerText;
public Text AIText;
public GameObject sceneManager;
void Update()
{
PlayerText.text = CurrentScore.ToString ();
AIText.text = CurrentAIScore.ToString ();
}
void OnTriggerEnter2D(Collider2D DoesScore)
{
if (DoesScore.gameObject.tag == "Player" && DoesScore.gameObject.isStatic)
{
CurrentScore++;
Debug.Log ("Player Scored!");
if (CurrentScore >= 9)
{
SceneManager.LoadScene ("PlayerWins");
}
}
if (DoesScore.gameObject.tag == "AI" && DoesScore.gameObject.isStatic)
{
CurrentAIScore++;
Debug.Log ("AI Scored!");
if (CurrentAIScore >= 9) {
SceneManager.LoadScene ("AIWins");
}
}
}
}
All tags are correctly wired up, triggers are active on the box colliders of the goals and are set to static. The score even initializes at ‘0’ for both players as it writes it in update(). I think it might have something to do with either the SceneManager or the Triggers. Im just not sure. Any help would be greatly appreciated.