aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-06-12 18:41:18 -0400
committerCameron Katri <me@cameronkatri.com>2021-06-12 18:41:18 -0400
commit40471cf464366a7f49110a31d00fec160856b60f (patch)
tree33f8f8ea1e6da3e2dbed8cd46b06e9bf5bb9cfbe /Assets/Scripts
parenta524f24128a4653bbc06eede2379107f9255faf9 (diff)
downloadgmtk-gamejam-40471cf464366a7f49110a31d00fec160856b60f.tar.gz
gmtk-gamejam-40471cf464366a7f49110a31d00fec160856b60f.tar.zst
gmtk-gamejam-40471cf464366a7f49110a31d00fec160856b60f.zip
Add sound effects for dribble and shoot
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Controllers/CameraController.cs2
-rw-r--r--Assets/Scripts/Controllers/GameController.cs7
-rw-r--r--Assets/Scripts/Controllers/Hoop.cs14
3 files changed, 20 insertions, 3 deletions
diff --git a/Assets/Scripts/Controllers/CameraController.cs b/Assets/Scripts/Controllers/CameraController.cs
index faffbe5..7d42be5 100644
--- a/Assets/Scripts/Controllers/CameraController.cs
+++ b/Assets/Scripts/Controllers/CameraController.cs
@@ -7,7 +7,7 @@ namespace Controllers
[SerializeField] private Transform target;
[SerializeField] private float speed;
- private void Update()
+ private void FixedUpdate()
{
transform.position = Vector3.MoveTowards(transform.position, new Vector3(target.transform.position.x, target.transform.position.y, -10f), Time.deltaTime * speed);
}
diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs
index 8dd6fc4..54a0425 100644
--- a/Assets/Scripts/Controllers/GameController.cs
+++ b/Assets/Scripts/Controllers/GameController.cs
@@ -21,11 +21,15 @@ namespace Controllers
[SerializeField] public Hoop PlayerHoop;
[SerializeField] public Hoop EnemyHoop;
+ [SerializeField] public AudioSource dribbleSound;
+
private void Awake()
{
player = new Player { isEnemy = false, controller = this };
enemy = new Player { isEnemy = true, controller = this };
ball.controller = this;
+ PlayerHoop.controller = this;
+ EnemyHoop.controller = this;
}
public struct Player
@@ -88,6 +92,7 @@ namespace Controllers
if (Vector2.Distance(controller.ball.transform.position, handPosition) >= 1f) return false;
controller.state = dribble;
+ controller.dribbleSound.Play();
Move(handPosition);
return true;
}
@@ -100,6 +105,7 @@ namespace Controllers
public bool Shoot(Transform playerTransform)
{
if (controller.state != dribble) return false; // We must be dribbling the ball to shoot it.
+ controller.dribbleSound.Stop();
controller.state = shoot;
controller.ball.Shoot(hoop.transform.position);
lastShotPosition = playerTransform.position;
@@ -109,6 +115,7 @@ namespace Controllers
internal void BallDropped()
{
+ dribbleSound.Stop();
state = State.Idle;
}
diff --git a/Assets/Scripts/Controllers/Hoop.cs b/Assets/Scripts/Controllers/Hoop.cs
index 58f7130..5633743 100644
--- a/Assets/Scripts/Controllers/Hoop.cs
+++ b/Assets/Scripts/Controllers/Hoop.cs
@@ -3,17 +3,27 @@ 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))
- Debug.Log("Swish!");
+ {
+ shotSound.Play();
+ if (this == controller.PlayerHoop)
+ controller.player.Score(Rim.transform.position);
+ else if (this == controller.EnemyHoop)
+ controller.enemy.Score(Rim.transform.position);
+ }
}
}
} \ No newline at end of file