]> git.cameronkatri.com Git - gmtk-gamejam.git/blob - Assets/Scripts/Controllers/Hoop.cs
Add VFX
[gmtk-gamejam.git] / Assets / Scripts / Controllers / Hoop.cs
1 using System;
2 using UnityEngine;
3
4 namespace Controllers
5 {
6 [RequireComponent(typeof(AudioSource))]
7 [RequireComponent(typeof(AudioSource))]
8 public class Hoop : MonoBehaviour
9 {
10 internal GameController controller;
11
12 [SerializeField] private BoxCollider2D Rim;
13 [SerializeField] private BoxCollider2D Net;
14 [SerializeField] private AudioSource shotSound;
15 [SerializeField] private AudioSource crowdSound;
16
17 private Animator HoopAnimator;
18
19 private void Awake() => HoopAnimator = GetComponentInChildren<Animator>();
20
21 private void OnTriggerEnter2D(Collider2D other)
22 {
23 if (other.GetComponent<Ball>() == null) return;
24
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))
27 {
28 HoopAnimator.Rebind();
29 shotSound.Play();
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);
34 crowdSound.Play();
35 }
36 }
37 }
38 }