In my code, the highscore is calculated by multiplying the base score by a multiplier that grows with every block destroyed and that resets when the ball touches the paddle or the lose collider. For this I access the class ball from gamestatus and for some reason I am not able to successfully implement the singleton on this, the ball would stop working, or the blocks would stop breaking, or the ball would randomly spawn in the middle of the lvl 2.
Is this use of static variable ok?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class GameStatus : MonoBehaviour
{
public TextMeshProUGUI scoreText;
[Range(0.5f,2f)]public float timeSpeed = 1f;
public static int currentScore = 0;
public float baseScoreValue = 100;
Ball ball;
// Start is called before the first frame update
void Start()
{
ball = FindObjectOfType<Ball>();
scoreText.text = currentScore.ToString();
}
// Update is called once per frame
void Update()
{
Time.timeScale = timeSpeed;
}
public void AddToScore()
{
currentScore += System.Convert.ToInt32(baseScoreValue * ball.comboMultiplier);
scoreText.text = currentScore.ToString();
}
}