Executing the test

Now that we have a pretty good idea of how the code works, let's see it in action. First things first, however. Let's make sure our component is properly set up. Select the Tree game object from the hierarchy, and its inspector should look similar to this:

The default settings for the component

As you can see, the state colors and box references have already been assigned for you, as well as the m_valueLabel variable. The m_targetValue variable has also been assigned for you via code. Make sure to leave it at (or set it to) 20 before you hit play. Play the scene, and you'll see your boxes lit up, as shown in the following ...

Get Unity 2017 Game AI Programming - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.