blob: 56337437f7e1adb39c40361fefab7f16ea1e863a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
using System;
using UnityEngine;
namespace Controllers
{
[RequireComponent(typeof(AudioSource))]
public class Hoop : MonoBehaviour
{
internal GameController controller;
[SerializeField] private BoxCollider2D Rim;
[SerializeField] private BoxCollider2D Net;
[SerializeField] private AudioSource shotSound;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.GetComponent<Ball>() == null) return;
if (Rim.IsTouching(other) && Net.IsTouching(other))
{
shotSound.Play();
if (this == controller.PlayerHoop)
controller.player.Score(Rim.transform.position);
else if (this == controller.EnemyHoop)
controller.enemy.Score(Rim.transform.position);
}
}
}
}
|