using System; using UnityEngine; namespace Controllers { [RequireComponent(typeof(AudioSource))] [RequireComponent(typeof(AudioSource))] public class Hoop : MonoBehaviour { internal GameController controller; [SerializeField] private BoxCollider2D Rim; [SerializeField] private BoxCollider2D Net; [SerializeField] private AudioSource shotSound; [SerializeField] private AudioSource crowdSound; private Animator HoopAnimator; private void Awake() => HoopAnimator = GetComponentInChildren(); private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent() == null) return; if (Rim.IsTouching(other) && Net.IsTouching(other)) { HoopAnimator.Rebind(); shotSound.Play(); if (this == controller.PlayerHoop) controller.player.Score(Rim.transform.position); else if (this == controller.EnemyHoop) controller.enemy.Score(Rim.transform.position); crowdSound.Play(); } } } }