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.
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);
}
}
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?
That’s how the code was set up when I downloaded the project files
But usually I don’t add private declaration to a Serialized Field
Ah, that makes sense! It’s been a while since I looked at the project files so I was just curious.
Awesome! I liked the part about restarting the game. I would have added the following code, as the function has never been called
private void CheckIfLevelComplete()
{
// Challenge 5:
if(allPlayerCubes.Count <= 0)
{
youWinText.SetActive(true);
Invoke("RestartGame", 3f);
}
}