O'Reilly logo

Unity Game Development Scripting by Kyle D'Aoust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing the GUI

Now, we will add the 2D GUI that we created in Chapter 2, GUI Time.

Adding the script

Drag-and-drop the GUI_2D script onto the First Person Controller. Since we already have everything coded, your work is almost done for the GUI! In the scene, create a new empty GameObject and name it Empty; this will be used by the script. If you don't have default values for your GUI_2D script, set them to these values:

  • Current HP to 100
  • Max HP to 100
  • Current Bar Length to 0
  • Current Level to 1
  • Max Experience to 100
  • Current Experience to 0
  • Current Exp Bar Length to 0
  • Max Exp Bar Length to 100

With all of this added, when you run the scene it should look like this:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required