We always want to give players clear and immediate feedback, so we'll start by adding in the logic for a win condition, as follows:
- Update GameBehavior to match the following code:
public class GameBehavior : MonoBehaviour
{
// 1
public bool showWinScreen = false;
private int _itemsCollected = 0;
public int Items
{
get { return _itemsCollected; }
set {
_itemsCollected = value;
if (_itemsCollected >= maxItems)
{
labelText = "You've found all the items!";
// 2
showWinScreen = true;
}
else
{
labelText = "Item found, only " + (maxItems -
_itemsCollected) + " more to go!";
}
}
}
// ... No changes needed ...
void OnGUI()
{
...