DOUBLE ROOM QUEST: ‘Then There Was None’ - Solutions

Quest: Double Room Quest
Challenge: Then There Was None

Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.

public class GameHandler : MonoBehaviour
{
    [SerializeField] private GameObject youWinText = null;

    [SerializeField] private List<PlayerMovement> allPlayerCubes = new List<PlayerMovement>();

    private void Start()
    {
        allPlayerCubes.AddRange(FindObjectsOfType<PlayerMovement>());
        youWinText.SetActive(false);
    }

    public void RemovePlayerCubeFromList(PlayerMovement thisCube)
    {
        allPlayerCubes.Remove(thisCube);
        CheckIfLevelComplete();
    }

    private void CheckIfLevelComplete()
    {
        if (allPlayerCubes.Count <= 0)
        {
            youWinText.SetActive(true);
        }
    }

    public void RestartGame()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
}
1 Like

It’s nice to see someone tackling these quests! I’m curious… is there a reason you use the private declaration with a Serialized Field or is it just a personal preference?

1 Like

That’s how the code was set up when I downloaded the project files :sweat_smile:
But usually I don’t add private declaration to a Serialized Field

Ah, that makes sense! :slight_smile: It’s been a while since I looked at the project files so I was just curious.