Did we win???

Or lose?? We have the basics setup for the game. We have a win condition, we can defend ourselves using the firing mechanism we built in earlier. We know that if the enemy player hits us enough we'll lose all our HP. But how do we update the game manager to reflect the loss condition?

Ok, so we update the GameBehavior script by adding a LossButton button object. Next we added an if statement in the setter object of the the HP variable. The if statement checks to see if the _playerHP variable is less then or equal to 0. If so, text is printed to the screen and sets the LossButton to active displaying it on the game screen. If not, an else statement prints out a different message and the game continues.

public int HP
    {
        get { return _playerHP; }
        set
        {
            _playerHP = value;
            HealthText.text = "Player Health: " + HP;
            
            if(_playerHP <= 0)
            {
                ProgressText.text = "You want another life with that?";
                LossButton.gameObject.SetActive(true);
                Time.timeScale = 0;
            }
            else
            {
                ProgressText.text = "Ouch... that's got to hurt.";
            }
            //Debug.LogFormat("Lives: {0}", _playerHP);
        }
    }
HP variable code block

That's a wrap on my first game in Unity. I'm going to export it with webgl and put it in the games section for everyone to enjoy. It should be a blast. This doesn't stop my learning journey. I haven't finished the book yet and I already have several more courses waiting in the wings. I'm starting to flush out some possibilities of games that I want to try to make slowly progressing my abilities.