using UnityEngine; public class BallBase : MonoBehaviour { public AudioClip spawnSound; public AudioClip bounceSound; public AudioClip hitSound; protected Animator animator; protected AudioSource audioSource; protected Vector2 speed; void OnTriggerEnter2D(Collider2D other) { if(other.gameObject.CompareTag("Bar")) { if (!audioSource.isPlaying) { audioSource.PlayOneShot(hitSound); } // Destroy all bar segments when the ball hits a bar. var barSegments = GameObject.FindGameObjectsWithTag("Bar"); foreach (var barSegment in barSegments) { Destroy(barSegment); } // Notify the player that the bar has been hit. var player = GameObject.FindGameObjectWithTag("Player"); if (player != null) { player.GetComponent().OnBarHit(); } } } }