diff options
author | Carson Katri <carson.katri@gmail.com> | 2021-06-12 19:50:29 -0400 |
---|---|---|
committer | Carson Katri <carson.katri@gmail.com> | 2021-06-12 19:50:29 -0400 |
commit | ca2356eb3f3c88745d5ecc646383f49ff301be90 (patch) | |
tree | 7251295eb9aeb08219db4e457fc6c475335f3700 /Assets/Scripts | |
parent | ac637ab644e3ee0c2307bc1cdb69d1f490852eeb (diff) | |
download | gmtk-gamejam-ca2356eb3f3c88745d5ecc646383f49ff301be90.tar.gz gmtk-gamejam-ca2356eb3f3c88745d5ecc646383f49ff301be90.tar.zst gmtk-gamejam-ca2356eb3f3c88745d5ecc646383f49ff301be90.zip |
Add scoreboard UI
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/Controllers/Ball.cs | 8 | ||||
-rw-r--r-- | Assets/Scripts/Controllers/GameController.cs | 25 |
2 files changed, 30 insertions, 3 deletions
diff --git a/Assets/Scripts/Controllers/Ball.cs b/Assets/Scripts/Controllers/Ball.cs index 45e607b..d9c85c2 100644 --- a/Assets/Scripts/Controllers/Ball.cs +++ b/Assets/Scripts/Controllers/Ball.cs @@ -11,6 +11,9 @@ namespace Controllers internal GameController controller; [SerializeField] private float shotForce; + + public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>(); + private Rigidbody2D _rigidbody; private void OnCollisionEnter2D(Collision2D other) { @@ -20,9 +23,8 @@ namespace Controllers public void Shoot(Vector3 target) { transform.right = (target - transform.position); - var rb = GetComponent<Rigidbody2D>(); - rb.velocity = Vector2.zero; - rb.AddForce((transform.right + (transform.up * 0.5f)) * shotForce); + Rigidbody.velocity = Vector2.zero; + Rigidbody.AddForce((transform.right + (transform.up * 0.5f)) * shotForce); } } } 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; } |