Hi! I love the course so far; it is great to find a course that doesn’t just run through endless boring exersizes on for loops and whatever. It really seems to get me on the way!
but after this lecture I got stuck on something. I believe I followed every step you took, but somehow I have a problem. My score does increase in the level that I played the run button in, and after finishing the level the game goes to the next scene, keeps the game status gameobject, destroys a game status gameobject, and continues playing. But in this second level, the score does not increase! it keeps the end score of the previous scene (83, since there was only one block). I let it go to game over, start new game, and I am back in my first scene. and there my score DOES increase again (with 83 points) and goes to the next level.
This is the same if I start with my second scene. Only in the scene that i started out with, the score increases…
any thoughts on what might be the problem? I’m pretty lost haha.
thank you so much in advance!
Tjebbe!
screen1|690x366
the code of my gamestatus:
> using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class GameStatus : MonoBehaviour {
// config params
[Range(0.1f, 10f)] [SerializeField] float gameSpeed = 1f;
[SerializeField] int pointsPerBlockDestroyed = 83;
[SerializeField] TextMeshProUGUI scoreText;
// state vars
[SerializeField] int currentScore = 000; // serialized for debugging
private void Awake()
{
int gameStatusCount = FindObjectsOfType<GameStatus>().Length;
if (gameStatusCount > 1)
{
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
}
}
private void Start()
{
scoreText.text = currentScore.ToString();
}
// Update is called once per frame
void Update () {
Time.timeScale = gameSpeed;
}
public void AddToScore()
{
currentScore += pointsPerBlockDestroyed;
scoreText.text = currentScore.ToString();
}
}
the code of my block:
> using System.Collections;
> using System.Collections.Generic;
> using UnityEngine;
>
> public class Block : MonoBehaviour {
> [SerializeField] AudioClip breakSound;
>
> //cached refs
> Level level;
> GameStatus gameStatus;
>
> private void Start()
> {
> level = FindObjectOfType();
> level.CountBreakableBlocks();
> gameStatus = FindObjectOfType();
> }
>
> private void OnCollisionEnter2D(Collision2D collision)
> {
> DestroyBlock();
> }
>
> private void DestroyBlock()
> {
> AudioSource.PlayClipAtPoint(breakSound, Camera.main.transform.position);
> Destroy(gameObject);
> level.BlockDestroyed();
> gameStatus.AddToScore();
> }
> }