As per the lesson, I’ve serialized pointsPerBlockDestroyed and currentScore in my GameStatus script, and that script has been added to my Game Status prefab. I can see those two fields in the Inspector, but they constantly stay at 0 (I’ve tried restarting Unity / Visual Studio, as well as rebooting). I just can’t figure out why they aren’t updating. Below are relevant screenshots and scripts.
Game Status Inspector
Console output
GameStatus.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameStatus : MonoBehaviour
{
// configuration parameters
[Range(0.1f, 10f)] [SerializeField] float gameSpeed = 1f;
[SerializeField] int pointsPerBlockDestroyed = 83;
// state variables
[SerializeField] int currentScore = 0;
// Update is called once per frame
void Update()
{
Time.timeScale = gameSpeed;
}
public void AddToScore()
{
currentScore += pointsPerBlockDestroyed;
Debug.Log(currentScore);
}
}
Block.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Block : MonoBehaviour
{
[SerializeField] AudioClip breakSound;
// Cached reference
Level level;
private void Start()
{
level = FindObjectOfType<Level>();
level.CountBreakableBlocks();
}
private void OnCollisionEnter2D(Collision2D collision)
{
DestroyBlock();
}
private void DestroyBlock()
{
FindObjectOfType<GameStatus>().AddToScore();
AudioSource.PlayClipAtPoint(breakSound, Camera.main.transform.position);
Destroy(gameObject);
level.BlockDestroyed();
}
}