namespace Controllers
{
+ [RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(AudioSource))]
public class Hoop : MonoBehaviour
{
[SerializeField] private BoxCollider2D Rim;
[SerializeField] private BoxCollider2D Net;
[SerializeField] private AudioSource shotSound;
+ [SerializeField] private AudioSource crowdSound;
private Animator HoopAnimator;
- private void Awake()
- {
- HoopAnimator = GetComponentInChildren<Animator>();
- }
+ private void Awake() => HoopAnimator = GetComponentInChildren<Animator>();
private void OnTriggerEnter2D(Collider2D other)
{
if (other.GetComponent<Ball>() == null) return;
- if (Rim.IsTouching(other) && Net.IsTouching(other))
+ // We don't want people shooting up the hoop so check the velocity of the ball to make sure it is going down.
+ if (Rim.IsTouching(other) && Net.IsTouching(other) && (other.GetComponent<Rigidbody2D>().velocity.y < 0))
{
HoopAnimator.Rebind();
shotSound.Play();
controller.player.Score(Rim.transform.position);
else if (this == controller.EnemyHoop)
controller.enemy.Score(Rim.transform.position);
+ crowdSound.Play();
}
}
}