Hello,
I have completed this section and I cannot run my game. I noticed the field breakableBlocks is not serialized in Inspector and I do not know why. I have this bug in console upon starting my game:
NullReferenceException: Object reference not set to an instance of an object
Block.Start () (at Assets/Scripts/Block.cs:15)
Here is my Block script:
public class Block : MonoBehaviour
{
[SerializeField] AudioClip destroySound;
//cached ref
Level level;
private void Start()
{
level = FindObjectOfType<Level>();
level.CountBreakableBlocks();
}
private void OnCollisionEnter2D(Collision2D collision)
{
AudioSource.PlayClipAtPoint(destroySound, Camera.main.transform.position);
Destroy(gameObject);
}
}
Here is my Level script:
public class Level : MonoBehaviour
{
[SerializeField] int breakableBlocks;
public void CountBreakableBlocks()
{
breakableBlocks++;
}
}
Here is Inspector view:
Cannot find the solution. Anyone could help?
Regards,
Paweł