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/CameraController.cs | 6 +++- Assets/Scripts/Controllers/GameController.cs | 27 +++++++++++++++-- Assets/Scripts/Controllers/Player/PlayerSegment.cs | 7 ++++- Assets/Scripts/Spotlight.cs | 35 ++++++++++++++++++++++ Assets/Scripts/Spotlight.cs.meta | 3 ++ 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 Assets/Scripts/Spotlight.cs create mode 100644 Assets/Scripts/Spotlight.cs.meta (limited to 'Assets/Scripts') diff --git a/Assets/Scripts/Controllers/CameraController.cs b/Assets/Scripts/Controllers/CameraController.cs index 7d42be5..8730c1c 100644 --- a/Assets/Scripts/Controllers/CameraController.cs +++ b/Assets/Scripts/Controllers/CameraController.cs @@ -6,10 +6,14 @@ namespace Controllers { [SerializeField] private Transform target; [SerializeField] private float speed; + [SerializeField] private GameController game; private void FixedUpdate() { - transform.position = Vector3.MoveTowards(transform.position, new Vector3(target.transform.position.x, target.transform.position.y, -10f), Time.deltaTime * speed); + if (game.player.IsShooting || game.enemy.IsShooting) // Track the ball when they shoot + transform.position = Vector3.MoveTowards(transform.position, new Vector3(game.ball.transform.position.x, game.ball.transform.position.y, -10f), Time.deltaTime * speed); + else // Track the player otherwise + 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 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; diff --git a/Assets/Scripts/Controllers/Player/PlayerSegment.cs b/Assets/Scripts/Controllers/Player/PlayerSegment.cs index 67b3ecf..aac0164 100644 --- a/Assets/Scripts/Controllers/Player/PlayerSegment.cs +++ b/Assets/Scripts/Controllers/Player/PlayerSegment.cs @@ -48,7 +48,12 @@ namespace Controllers.Player private void OnCollisionEnter2D(Collision2D other) { - if (callFoulOnContact && game.player.HasBall && other.gameObject.CompareTag("Ground")) + if (!callFoulOnContact) return; + Debug.Log("ENTERED"); + Debug.Log(other.gameObject.CompareTag("Ground")); + Debug.Log(game.player.HasBall); + Debug.Log("---"); + if (game.player.HasBall && other.gameObject.CompareTag("Ground")) game.player.Foul("LOOSE BALL FOUL"); } } diff --git a/Assets/Scripts/Spotlight.cs b/Assets/Scripts/Spotlight.cs new file mode 100644 index 0000000..95a0f5e --- /dev/null +++ b/Assets/Scripts/Spotlight.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections; +using UnityEngine; +using Random = UnityEngine.Random; + +public class Spotlight : MonoBehaviour +{ + [SerializeField] private int duration; + [SerializeField] private float speed; + private Vector2 targetPosition; + + private void Start() + { + StartCoroutine(RandomMove()); + } + + private void FixedUpdate() + { + var target = new Vector3(targetPosition.x, targetPosition.y, transform.position.z); + if (transform.position == Vector3.zero) + transform.position = target; + else + transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * speed); + } + + private IEnumerator RandomMove() + { + for (var i = 0; i < duration; i++) + { + targetPosition = new Vector2(Random.Range(-12f, 12f), Random.Range(3.5f, 6.2f)); + yield return new WaitForSeconds(.8f); + } + Destroy(gameObject); + } +} diff --git a/Assets/Scripts/Spotlight.cs.meta b/Assets/Scripts/Spotlight.cs.meta new file mode 100644 index 0000000..66d1cb3 --- /dev/null +++ b/Assets/Scripts/Spotlight.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 009879624ac3468bb1654968528afdc3 +timeCreated: 1623603680 \ No newline at end of file -- cgit v1.2.3-56-ge451