]> git.cameronkatri.com Git - gmtk-gamejam.git/blob - Assets/Scripts/Controllers/Ball.cs
Airhorn at game end, better dribble, ball hit sound
[gmtk-gamejam.git] / Assets / Scripts / Controllers / Ball.cs
1 using UnityEngine;
2
3 namespace Controllers
4 {
5 [RequireComponent(typeof(Rigidbody2D))]
6 [RequireComponent(typeof(CircleCollider2D))]
7 public class Ball : MonoBehaviour
8 {
9 internal GameController controller;
10
11 [SerializeField] private float shotForce;
12 [SerializeField] private AudioSource ballHitSound;
13 [SerializeField] private AudioClip ballHitClip;
14
15 public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
16 private Rigidbody2D _rigidbody;
17
18 private void OnCollisionEnter2D(Collision2D other)
19 {
20 ballHitSound.PlayOneShot(ballHitClip);
21 controller.BallDropped();
22 }
23
24 public void Shoot(Hoop target, float time)
25 {
26 transform.localRotation = Quaternion.identity;
27 Rigidbody.velocity = (Vector2)((target.transform.position - transform.position).normalized + transform.up * Mathf.Clamp(time, 0f, 1f)) * shotForce;
28 }
29 }
30 }