[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;
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;
public bool HasBall => controller.state == dribble;
+ public bool IsShooting => controller.state == shoot;
+
/// <summary>
/// When dribbling, move the ball with the player.
/// </summary>
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));
}
}
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<Rigidbody2D>().velocity = Vector2.zero;