From 65975146e07e33aa5cf5de83bee76c537ba787e3 Mon Sep 17 00:00:00 2001 From: Carson Katri Date: Sun, 13 Jun 2021 13:14:23 -0400 Subject: Add VFX --- Assets/Scripts/Controllers/GameController.cs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'Assets/Scripts/Controllers/GameController.cs') diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs index c9cb0ce..35e6b62 100644 --- a/Assets/Scripts/Controllers/GameController.cs +++ b/Assets/Scripts/Controllers/GameController.cs @@ -46,6 +46,11 @@ namespace Controllers [SerializeField] public AudioSource dribbleSound; [SerializeField] public AudioSource airhornSound; + [Header("VFX")] + [SerializeField] private GameObject twoPointVFX; + [SerializeField] private GameObject threePointVFX; + [SerializeField] private GameObject spotlightVFX; + [Header("UI")] [SerializeField] private Text playerScoreText; [SerializeField] private Text enemyScoreText; @@ -148,14 +153,20 @@ namespace Controllers if (Vector2.Distance(lastShotPosition, Rim) >= 10) { score += 3; + controller.ParticleEffect(true, hoop); } else { score += 2; + controller.ParticleEffect(false, hoop); } + + // Make two spotlights. + Instantiate(controller.spotlightVFX); + Instantiate(controller.spotlightVFX); // They made a shot! Now respawn the players and give possession to the opposite player. - controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, $"{controller.player.score}-{controller.enemy.score}"); + controller.StartCoroutine(controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, $"{controller.player.score}-{controller.enemy.score}")); } private State dribble => isEnemy ? State.EnemyDribble : State.PlayerDribble; @@ -165,6 +176,8 @@ namespace Controllers public bool HasBall => controller.state == dribble; + public bool IsShooting => controller.state == shoot; + /// /// When dribbling, move the ball with the player. /// @@ -219,7 +232,7 @@ namespace Controllers public void Foul(string reason) { // Give the other player the ball on a foul. - controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, reason); + controller.StartCoroutine(controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, reason, false)); } } @@ -231,9 +244,17 @@ namespace Controllers state = State.Idle; } - private void Respawn(Possession possession, string message) + private void ParticleEffect(bool threePts, Hoop hoop) + { + var vfx = Instantiate(threePts ? threePointVFX : twoPointVFX); + vfx.transform.position = hoop.transform.position; + } + + private IEnumerator Respawn(Possession possession, string message, bool wait = true) { BallDropped(); + + yield return new WaitForSeconds(wait ? 0.5f : 0f); // Wait a slight bit before respawning so they can see the VFXs. PlayerSpawnPoints.body.transform.position = new Vector3(PlayerSpawnPoints.character.position.x, PlayerSpawnPoints.character.position.y, PlayerSpawnPoints.body.transform.position.y); PlayerSpawnPoints.body.GetComponent().velocity = Vector2.zero; -- cgit v1.2.3-56-ge451