aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts/Controllers/GameController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Controllers/GameController.cs')
-rw-r--r--Assets/Scripts/Controllers/GameController.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs
index e1af95c..3260fb2 100644
--- a/Assets/Scripts/Controllers/GameController.cs
+++ b/Assets/Scripts/Controllers/GameController.cs
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
+using UnityEngine.UI;
namespace Controllers
{
@@ -19,11 +20,17 @@ namespace Controllers
/// </summary>
[SerializeField] public Ball ball;
+ [Header("Hoops")]
[SerializeField] public Hoop PlayerHoop;
[SerializeField] public Hoop EnemyHoop;
+ [Header("SFX")]
[SerializeField] public AudioSource dribbleSound;
+ [Header("UI")]
+ [SerializeField] private Text playerScoreText;
+ [SerializeField] private Text enemyScoreText;
+
private void Awake()
{
player = new Player { isEnemy = false, controller = this };
@@ -33,6 +40,17 @@ namespace Controllers
EnemyHoop.controller = this;
BallAnimation = ball.GetComponentInChildren<Animator>();
}
+
+ private void Start()
+ {
+ UpdateUI();
+ }
+
+ private void UpdateUI()
+ {
+ playerScoreText.text = $"{player.score}";
+ enemyScoreText.text = $"{enemy.score}";
+ }
public struct Player
{
@@ -59,6 +77,8 @@ namespace Controllers
{
score += 2;
}
+
+ controller.UpdateUI();
}
private State dribble => isEnemy ? State.EnemyDribble : State.PlayerDribble;
@@ -95,6 +115,9 @@ namespace Controllers
controller.BallAnimation.enabled = false;
controller.dribbleSound.Play();
Move(handPosition);
+
+ controller.ball.Rigidbody.bodyType = RigidbodyType2D.Kinematic;
+
return true;
}
@@ -109,6 +132,7 @@ namespace Controllers
controller.BallAnimation.enabled = true;
controller.dribbleSound.Stop();
controller.state = shoot;
+ controller.ball.Rigidbody.bodyType = RigidbodyType2D.Dynamic;
controller.ball.Shoot(hoop.transform.position);
lastShotPosition = playerTransform.position;
return true;
@@ -119,6 +143,7 @@ namespace Controllers
{
BallAnimation.enabled = true;
dribbleSound.Stop();
+ ball.Rigidbody.bodyType = RigidbodyType2D.Dynamic;
state = State.Idle;
}