5 [RequireComponent(typeof(Rigidbody2D))]
6 [RequireComponent(typeof(CircleCollider2D))]
7 public class Ball : MonoBehaviour
9 internal GameController controller;
11 [SerializeField] private float shotForce;
12 [SerializeField] private AudioSource ballHitSound;
13 [SerializeField] private AudioClip ballHitClip;
15 public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
16 private Rigidbody2D _rigidbody;
18 private void OnCollisionEnter2D(Collision2D other)
20 ballHitSound.PlayOneShot(ballHitClip);
21 controller.BallDropped();
24 public void Shoot(Hoop target, float time)
26 transform.localRotation = Quaternion.identity;
27 Rigidbody.velocity = (Vector2)((target.transform.position - transform.position).normalized + transform.up * Mathf.Clamp(time, 0f, 1f)) * shotForce;