Scripting for dynamic content
Now that your HUD has been completed, it is time to consider how the information on the HUD is updated. The following elements of our HUD require scripting so that they are dynamically updated during the game:
- Cucumber Man's health
- Number of Cucumber Man lives remaining
- Points
- Number of cherries in Cucumber Man's inventory
- Number of cucumbersÂ
- Number of Cucumber Beetles
In this section, we will lay the groundwork for updating the HUD information.Â
Scripting the cucumber count
Let's start with our cucumber count:
- In the
Hierarchy
panel, selectÂHUD_Canvas
|Cucumber_Count
- In the
Inspector
panel, click theAdd Component
button - Select
New Script
and name the scriptCucumberManager
- Edit the script
With the script open, make the necessary modifications to match the script provided, as follows:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; publicclassCucumberManager:MonoBehaviour{ publicintcurrentCucumberCount; TextCucumber_Count...