Implementing defeat
There are two game conditions in which the player can lose the game. The first condition is if there are no cucumbers left in the game. The second condition is if all three lives are gone. Let's look at each of these defeat conditions separately.
Scripting defeat based on no cucumbers remaining
Our CucumberManager
script already keeps track of the number of cucumbers in the game, so we merely need to give that script's currentCucumberCount
class variable the static modifier and then update our VictoryManager
script. Here are the steps.
Edit the
CucumberManager
script so thecurrentCucumberCount
variable declaration is as follows:
public static int currentCucumberCount;
- In theÂ
Awake()
 method, changeÂcurrentCucumberCount = 0;
 toÂcurrentCucumberCount = 1;
. This will help ensure the game does not think there are no cucumbers when the game starts. - Add the following statement at the end of theÂ
Update()
 method,currentCucumberCount = cucumbers.Length;
. This will keep the counter...