using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Block : MonoBehaviour
{
[SerializeField] AudioClip breaksound;
private void OnCollisionEnter2D(Collision2D collision)
{
AudioSource.PlayClipAtPoint(breaksound, Camera.main.transform.position);
Destroy(gameObject);
}
}
every time the ball hit the block its tell me a problem and the block didn’t destroy
{
NullReferenceException: Object reference not set to an instance of an object
Block.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/Scripts/Block.cs:9)
}
when i remove this line
AudioSource.PlayClipAtPoint(breaksound, Camera.main.transform.position);
its working fine again