+ private void Respawn(Possession possession, string message)
+ {
+ BallDropped();
+
+ 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;
+
+ if (PlayerSpawnPoints.secondBody is { })
+ {
+ if (PlayerSpawnPoints.secondCharacter is { })
+ PlayerSpawnPoints.secondBody.transform.position = new Vector3(PlayerSpawnPoints.secondCharacter.position.x, PlayerSpawnPoints.secondCharacter.position.y, PlayerSpawnPoints.body.transform.position.y);
+ PlayerSpawnPoints.secondBody.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
+ }
+
+ PlayerSpawnPoints.body.transform.localRotation = Quaternion.identity;
+ EnemySpawnPoints.body.transform.position = new Vector3(EnemySpawnPoints.character.position.x, EnemySpawnPoints.character.position.y, EnemySpawnPoints.body.transform.position.y);
+ ball.transform.position = possession switch
+ {
+ Possession.Player => new Vector3(PlayerSpawnPoints.ball.position.x, PlayerSpawnPoints.ball.position.y, ball.transform.position.y),
+ Possession.Enemy => new Vector3(EnemySpawnPoints.ball.position.x, EnemySpawnPoints.ball.position.y, ball.transform.position.y),
+ _ => ball.transform.position
+ };
+
+ // Set a cooldown so they can stop trying to wrangle the player while it respawns.
+ StartCoroutine(RespawnCooldown(possession, message));
+ }
+
+ private IEnumerator RespawnCooldown(Possession possession, string message)
+ {
+ // Show the new score.
+ var possessionText = possession == Possession.Player ? "HOME" : "AWAY";
+ ShowModal($"{message}\n{possessionText}'S POSSESSION");
+
+ freezeMotion = true;
+
+ yield return new WaitForSeconds(1f);
+
+ HideModal();
+
+ freezeMotion = false;
+ }
+
+ private void ShowModal(string text)
+ {
+ if (gameover) return;
+ resultOverlay.SetActive(true);
+ resultText.text = text;
+ }
+
+ private void HideModal()
+ {
+ if (gameover) return;
+ resultOverlay.SetActive(false);
+ }
+
+ public void Restart() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
+
+ public void MainMenu() => SceneManager.LoadScene("Menu");
+