Game Development Reference
In-Depth Information
If you now add a
Text
control to your scene and then add the script to it,
(you can just add the script to a GameObject and it will automatically add the
Text
component, thanks to the
RequireComponent
attribute), you will then get
your basic
FPS
output as shown here:
You could also use rich text to draw the text, if you so wish, if you have it enabled
in the
Text
settings.
Adding interaction with input
Displaying text is all well and good, but what about when you need the player
to enter some text? Using the native platforms input features is OK but it breaks
the illusion of the world within by breaking out of the game and showing a bulky
platform input box.
To give a better look and feel, Unity have provided a base text
Input
component,
which is best used when combined with the
Text
control (The
Input Field
control
will add a Text component by default) along with an
Image
component as a
background. (Although you can add it to any other UI control if you wish.)
When you add an
Input Field
control, navigate to
Create
|
UI
|
InputField
in the
Hierarchy
window (or from the multitude of options as detailed at the start of this
section) you will see the following additional options in the
Inspector
window: