Unity 'Hello World'
Printing to console
-
Create new project (set
Template
to2D
). -
Inside
Assets
create scripthello.cs
with the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hello : MonoBehaviour {
// Use this for initialization
void Start () {
print("Hello World");
}
// Update is called once per frame
void Update () {
}
}
That is:
- right click in
Assets
areaCreate > C# Script
, - rename it
Hello.cs
, - double click on it,
- add
print("Hello World");
insideStart
method, - save it and build it (just in case).
-
Attach script
hello.cs
toSampleScene
-Main Camera
by drag-and-drop the script ontoMain Camera.
-
Save Scene and run (press
>
button). -
Switch to
Console
tab in order to see something like
[13:29:19] Hello World
UnityEngine.MonoBehaviour:print(Object)
Printing to Scene
In order to print inside the scene you should add a method
void OnGUI()
{
GUILayout.Label("Hello World");
}
into class Hello
. So the script Hello.cs
should like like:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hello : MonoBehaviour {
// Use this for initialization
void Start () {
print("Hello World");
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
GUILayout.Label("Hello World");
}
}
”