You don't have to read all the code, my question is a bit further down. Thank you for helping :s
public GameObject CanvasGame;
public GameObject canvasRestart;
public GameObject WinTxt;
public GameObject LoseTxt;
public GameObject scoreScripte;
public GameObject puckScript;
public GameObject playerMovement1;
public GameObject playerMovement2;
public void ShowRestartCanvas(bool didP1win)
{
Time.timeScale = 0;
CanvasGame.SetActive(false);
canvasRestart.SetActive(true);
if (didP1win)
{
WinTxt.SetActive(true);
LoseTxt.SetActive(false);
}
else
{
WinTxt.SetActive(false);
LoseTxt.SetActive(true);
}
}
using UnityEngine.UI;
using UnityEngine;
public class ScoreScript : MonoBehaviour
{
public enum Score
{
P1Score, P2Score
}
public Text P1ScoreTxt, P2ScoreTxt;
public UIManager uiManager;
public int MaxScore;
#region Scores
private int p1Score, p2Score;
private int P1Score
{
get { return p1Score; }
set
{
p1Score = value;
if (value == MaxScore)
uiManager.ShowRestartCanvas(true);
}
}
private int P2Score
{
get { return p2Score; }
set
{
p2Score = value;
if (value == MaxScore)
uiManager.ShowRestartCanvas(false);
}
}
#endregion
public void Increment(Score whichScore)
{
if (whichScore == Score.P1Score)
{
P1ScoreTxt.text = (++P1Score).ToString();
}
else
{
P2ScoreTxt.text = (++P2Score).ToString();
}
}
}
That first bunch of code is my UI Manager the second one is my Score Script. The error is:
NullReferenceException: Object reference not set to an instance of an object ScoreScript.set_P1Score (System.Int32 value) (at Assets/Scripts/ScoreScript.cs:26)
The UI does not pop up when the MaxScore value is met.
The lines that the error is referencing to are:
uiManager.ShowRestartCanvas(false);
uiManager.ShowRestartCanvas(true);
I tried but couldn't find the solution which is prob are easy one, I'm grateful for any help.