Ist there some unity specific disadvantages if I use just a regular “handmade” singleton instead?
Here is my example
1 My score container:
public class PlayerScoreSingleton
{
private PlayerScoreSingleton() { }
public int points = 0;
private static PlayerScoreSingleton instance = null;
public static PlayerScoreSingleton Instance {
get {
if (instance == null) {
instance = new PlayerScoreSingleton();
}
return instance;
}
}
}
2 here how I use it:
public class GameController : MonoBehaviour
{
[Range(0, 10)][SerializeField] float gameSpeed = 1f;
[SerializeField] int blockPoints = 10;
[SerializeField] TextMeshProUGUI scoreUI;
private PlayerScoreSingleton scorePointsContainer;
public void Start() {
this.scorePointsContainer = PlayerScoreSingleton.Instance;
this.updateGui();
}
public void addToScore() {
this.scorePointsContainer.points += this.blockPoints;
this.updateGui();
}
private void updateGui() {
this.scoreUI.text = this.scorePointsContainer.points.ToString();
}
}
Are there some problems with that approach? Am I doing something against some not so obvious Unity mechanics or is it a legit solution?