Files
Barrack-Unity/Assets/Scripts/Game/Balls/BallBase.cs
T

41 lines
943 B
C#

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"))
{
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<Player>().OnBarHit();
}
}
}
}