Exemple #1
0
    /*
     * Allows the player to restart the level they are currently on.
     */
    public void RestartLevel(bool dead = false)
    {
        if (dead)
        {
            CheckPoint lastCheckPoint = checkPointManager.GetClosestCheckPoint(playerControl.transform.position);

            playerControl.ResetPositions();

            playerRigidbody.MovePosition(lastCheckPoint.GetCheckPointPosition());

            // Reset the player's velocity and looking angle.
            playerRigidbody.velocity = Vector3.zero;
            playerControl.SetCameraRotation(new Vector2(lastCheckPoint.GetRespawnRotation(), 0f));

            // If rewind is enabled, these methods are called before the rewind begins.
            if (!RewindEnabled)
            {
                ResetPlayer();
                ResetLevelObjects();
            }
        }
        else
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }