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