6 [RequireComponent(typeof(AudioSource))]
7 [RequireComponent(typeof(AudioSource))]
8 public class Hoop : MonoBehaviour
10 internal GameController controller;
12 [SerializeField] private BoxCollider2D Rim;
13 [SerializeField] private BoxCollider2D Net;
14 [SerializeField] private AudioSource shotSound;
15 [SerializeField] private AudioSource crowdSound;
17 private Animator HoopAnimator;
19 private void Awake() => HoopAnimator = GetComponentInChildren<Animator>();
21 private void OnTriggerEnter2D(Collider2D other)
23 if (other.GetComponent<Ball>() == null) return;
25 // We don't want people shooting up the hoop so check the velocity of the ball to make sure it is going down.
26 if (Rim.IsTouching(other) && Net.IsTouching(other) && (other.GetComponent<Rigidbody2D>().velocity.y < 0))
28 HoopAnimator.Rebind();
30 if (this == controller.PlayerHoop)
31 controller.player.Score(Rim.transform.position);
32 else if (this == controller.EnemyHoop)
33 controller.enemy.Score(Rim.transform.position);