Book Image

Creating E-Learning Games with Unity

By : David Horachek
Book Image

Creating E-Learning Games with Unity

By: David Horachek

Overview of this book

Table of Contents (17 chapters)
Creating E-Learning Games with Unity
About the Author
About the Reviewers

Exploring UnityScript and the GUIButton object

The Unity Editor is laid out with an internal GUI-specification language called UnityGUI. This API is only accessible to Unity game programmers from within C# (and JavaScript) code, unlike the previous GUI elements that can be placed and adjusted within the editor itself at design time. We can use this to place buttons, textures, pop-up windows, tooltips, and many other UI primitives. The difference in use from the previous examples is that the elements are instanced and placed entirely from the script rather than at design time in the editor. For our dialog pop-up Prefabs, we will explore the GUI.Button class.

Using UnityGUI

To use the UnityGUI functionality, we must invoke the commands from within a special callback, OnGUI(). As this function is not created by default when you create a new C# script in Unity, you need to add it yourself. The Unity Engine will invoke this method automatically when GUI elements are to be redrawn; so, we put our...