Hi! Great course so far! Thank you for that.
I have a question about the solution of the AddToScore challenge. I’m still new to coding and as English is not my native language I might have some trouble with the terminology. I hope that you understand what I mean here.
So, my solution was a bit different from the one used in the video. I put the FindObjectOfType into the Start method and only called for gameStatus.AddToScore in the DestroyBlock method. After the challenge my Block.cs script was like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Block : MonoBehaviour
{
[SerializeField] AudioClip destroyBlockSound;
// Cached reference
Level level;
GameStatus gameStatus;
private void Start()
{
level = FindObjectOfType<Level>();
gameStatus = FindObjectOfType<GameStatus>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
DestroyBlock();
}
private void DestroyBlock()
{
AudioSource.PlayClipAtPoint(destroyBlockSound, Camera.main.transform.position);
Destroy(gameObject);
gameStatus.AddToScore();
level.BlockDestroyed();
}
}
I tested and it works like a charm. However I’d like to know if there are any significant benefits for using the solution shown on the lecture video.
Thanks!