I have an issue where the serialized field ‘Current Score’ doesn’t update when i test-play the game. I’ve included a Debug.log(currentScore); to see if it’s adding the score and it does just fine. here is the code for my gamestatus.cs:
public class GameStatus : MonoBehaviour {
// Configuration parameters
[Range(.01f, 10f)] [SerializeField] float gameSpeed;
[SerializeField] int pointPerBlock = 10;
// State variables
[SerializeField] int currentScore = 0;
// Update
void Update () {
Time.timeScale = gameSpeed;
}
public void AddToScore()
{
currentScore += pointPerBlock;
Debug.Log(currentScore);
}
}
and here is the code for my brick.cs:
public class Brick : MonoBehaviour {
public Sprite[] hitSprites;
private int timesHit;
void Start () {
timesHit = 0;
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ball")
{
timesHit++;
FindObjectOfType<GameStatus>().AddToScore();
HandleHits();
}
}
void HandleHits()
{
int maxHits = hitSprites.Length;
if (timesHit >= maxHits)
{
Destroy(gameObject);
}
else
{
LoadSprites();
}
}
void LoadSprites()
{
int spriteIndex = timesHit;
GetComponent<SpriteRenderer>().sprite = hitSprites[spriteIndex];
}
}
I’ve ran through this 3 times. each time erasing the changes and starting this section over to see if maybe I had missed something. Still the results are the same. Any thoughts?