Unity 5 Hello World!
10/12/2015 9:07 PM
The common way to learn a new language or a programming framework is to start with a simple “Hello World!” tutorial…
The first step is to download and install Unity 5.
Select Projects then NEW.
Call the project HelloWorldProject, select 2D and click the Create project button.
When it opens, ensure that you have Default layout selected.
From the menu bar, select GameObject then UI then Text.
A Canvas with a Text object and an EventSystem will appear.
Hold the Alt and right click-drag to zoom out (or click in the scene and scroll out using your mouse wheel).
Zoom out until you can see the Text Box.
Click on the Text Box and drag it until it is on the Canvas.
Ensure that the Rect tool is selected.
Select the Text Box, and in the Text section of its properties (in the Inspector), enter the words “Hello World!”.
Click the Play button.
The text will display.
Click the Play button again to stop the program and return to design mode.
Programmatically Create Hello World!
Select the Rect tool, select the Text Box, and in its properties (in the Inspector), select Add Component.
Scroll down to the bottom of the list and select the arrow next to New Script.
Enter TextController for the Name, ensure C Sharp is selected for the language, and click the Create and Add button.
The TextController script will be created and display in the Assets folder.
The script will also be attached to the TextBox.
Double-click on the TextController script in the Assets folder to open it.
The script editor will open.
Change all the code to the following:
public class TextController : MonoBehaviour
public Text TextBoxText;
// Use this for initialization
// Update is called once per frame
TextBoxText.text = "Hello World! (From Code)";
Save the code.
Switch back to the Unity editor and click on the Text Box to select it.
Drag the Text from the Hierarchy to the box next to Text Box Text property in the Text Controller that is attached to the TextBox.
(This sets the Text Box as the TextBoxText property in the script we created. That script will set the text of the Text Box)
Run the scene and see the result.
Save The Scene
From the menu, select File then Save Scene as…
Enter Main for the File name and click Save.
The scene will save in the Assets folder.
Double-clicking on a scene in the Assets folder will open that scene.
Beginner Tutorial: A Unity 5 Number Guessing Game
You can download the code from the Download page.
Unity 5 (or higher) is required to run the sample code.