Professional Documents
Culture Documents
As of 4/20/2020
Bookmarks
Tutorials
Brackeys - https://www.youtube.com/user/Brackeys
Unity tutorials to allow anyone - no matter their budget - to create top-quality games.
Develop your skills and your career with resources to learn at your own pace, or with Unity experts, at every
stage of learning.
Free Assets
Unity Asset Store - https://assetstore.unity.com/
Why Unity?
1. Gaming industry is $9.6 Billion in investments as of 2019. Unity is used for popular games like Pokemon Go,
Hearthstone, Call of Duty Mobile
2. Popular movies are made with Unity like Lion King, Ready Player One, Jungle Book
3. Not just games but also applications software for cars, VR, and apps
4. Easy to use, HUGE friendly dev community with tutorials and answers to all sorts of questions
5. Build on multiple platforms like mobile to show off to friends, family, or interviewers
6. Free!
Overview
1. Starting a project
2. Navigating Unity UI
3. Creating a game
4. Building Project
Hand (Q or hold right click) – drag or pan the view of the scene
The following affects the selected Game Object’s Transform Component
o Move (W) – move selected game object
o Rotate (E) – change rotation of selected game object
o Scale (R) – change the size selected Game Object (origin is center of Game Object)
o Rect (T) – change size (based on edges)
o Move, Rotate, or Scale (Y) – multi purpose (you can move or rotate selected game object)
Play – Play current game scene. Clicking play while game scene is playing stops play mode
Pause – Pause game scene that is playing
Creating a Game
Add Game objects to scene
Drag assets from Project tab to Scene.
You can change the color of sprites from the Inspector tab by clicking the Color then selecting the desired color on the
pop-up window (Click the X of the pop-up window to close it).
Think of nested game objects as combined as one so that transform actions (scale, move, rotate, etc.) on the parent
game object will affect the children. You can create a prefab (or blueprint) of this parent game object with children.
Create a script by right clicking on Project Tab under your desired scripts folder, then select Create, then select C# Script.
Select the Game Object in the Hierarchy Tab (or by clicking on the game object in the scene) to show the Game object’s
details on the Inspector Tab, then you can add this script to a Game Object in 2 ways.
1. On inspector tab, select Add Component, type the name of the script, then select the script, OR
2. drag the new C# Script under one of the other components of the selected Game object under the Inspector tab
Edit Scripts
Double Click on a script to add code into it so that any Game Object with the attached script has its functionality.
Create Prefabs
Drag a Game Object from the Hierarchy Tab into Project Tab (preferably Prefab folder) to create a prefab.
Now you can create clones of this new Game Object just by dragging it to the scene.
The prefab editor allows you to make changes later on a prefab and the changes will apply to every instance of the
prefab.
Add Audio
You can add background music and sound effects to your game.
public AudioSource sound; // On the editor, drag the game object with the sound source into this
public variable
Add UI
UI elements like Images, Buttons, text, and various interactable elements can be added to the game, they will be under a
Canvas Game Object.
Create UI
To create a UI element, right click on Hierarchy tab, select UI, then select desired UI to create – Text, Button, Image, etc.
If a Canvas Game object already exists, the new UI element will be created as a child of the canvas, otherwise a new
Canvas game object will automatically be created.
Position UI
It is best practice to use anchors to position UI elements to cater to different display resolutions
a.
3. then hold Alt + Shift and select with Mouse 1 desired location of UI
Useful UI elements
The following are useful UI elements you can create and use:
Text
You can use a Text UI to create a title.
1. Right click on Hierarchy, select UI, then Text. You can change the parameters (font, color, size, alignment, etc.) of
this new text game object in its Text (Script) component via the Inspector.
a. NOTE: If the font is too big, the text will disappear. Adjust the size of the text box using the Rect tool
(shortcut T) on the Scene view
2. Position the text UI using the anchors (see above).
Buttons
You can create UI buttons for different things like Start or Exit Game button
a.
5. Click on No Function, then select the script name on the list, then select the function you want called when the
button is clicked.
Building a Project
To build your project:
Destroy
To destroy game object, Add the following script to the Game Object
Destroy(gameObject, 0.1f); // Destroy game object after 0.1 time
Events
Events are specialized delegates useful to alert other classes that something has happened. They work similarly to public
multiclass delegates.
Delegate Event
Use this to create delegate events
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
3. Create scripts that subscribe to the event and also triggers when the event occurs
a. In this example add score function is called when the event occurs.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public AudioSource sound; // On the editor, drag the game object with the sound source into this
public variable
sound = GetComponent<AudioSource>();
}
Instantiate
Use the following script to create a Game Object during run time.
using UnityEngine;
using System.Collections;
Instantiate projectiles
Shooting projectiles using script
Syntax:
public static Object Instantiate(Object original);
public static Object Instantiate(Object original, Transform parent);
public static Object Instantiate(Object original, Transform parent, bool instantiateInWorldSpace);
using UnityEngine;
using System.Collections;
Scene Change
Tags: change map change Level Change Scene load scene load level
Use script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
Touch
Touch controls script
Terms
Editor – this is the Unity interface where you can create your game
Game Object – any object in the scene that has a transform and can have components
Hierarchy – this is the list of game objects that is in the game scene. Selecting a game object in the hierarchy will display
its components on the Inspector tab
UI – User Interface
Unity Cheat sheet
As of 2/9/2020
Bookmarks
Tutorials
Brackeys - https://www.youtube.com/user/Brackeys
· Unity tutorials to allow anyone - no matter their budget - to create top-quality games.
· Develop your skills and your career with resources to learn at your own pace, or with Unity experts, at
every stage of learning.
Free Assets
Unity Asset Store - https://assetstore.unity.com/
Why Unity?
1. Gaming industry is $9.6 Billion in investments as of 2019. Unity is used for popular games like Pokemon
Go, Hearthstone, Call of Duty Mobile
2. Popular movies are made with Unity like Lion King, Ready Player One, Jungle Book
3. Not just games but also applications software for cars, VR, and apps
4. Easy to use, HUGE friendly dev community with tutorials and answers to all sorts of questions
5. Build on multiple platforms like mobile to show off to friends, family, or interviewers
6. Free!
Overview
1. Starting a project
2. Navigating Unity UI
3. Creating a game
4. Building Project
2. Click New
3. Change Project Name, Save Location, and choose a template (2D, 3D, etc.), then select Create
Navigating Unity UI
Tool bar
· Hand (Q or hold right click) – drag or pan the view of the scene
o Scale (R) – change the size selected Game Object (origin is center of Game Object)
o Move, Rotate, or Scale (Y) – multi purpose (you can move or rotate selected game object)
· Play – Play current game scene. Clicking play while game scene is playing stops play mode
Creating a Game
Add Game objects to scene
Drag assets from Project tab to Scene.
You can change the color of sprites from the Inspector tab by clicking the Color then selecting the desired color
on the pop-up window (Click the X of the pop-up window to close it).
Parent and Child game objects
You can nest game objects with one another. From the hierarchy, you can drag one game object and drop it on
another game object to make the dragged and dropped game object a child of the other game object.
Think of nested game objects as combined as one so that transform actions (scale, move, rotate, etc.) on the
parent game object will affect the children. You can create a prefab (or blueprint) of this parent game object
with children.
Create a script by right clicking on Project Tab under your desired scripts folder, then select Create, then select
C# Script. Select the Game Object in the Hierarchy Tab (or by clicking on the game object in the scene) to
show the Game object’s details on the Inspector Tab, then you can add this script to a Game Object in 2 ways.
1. On inspector tab, select Add Component, type the name of the script, then select the script, OR
2. drag the new C# Script under one of the other components of the selected Game object under the
Inspector tab
Edit Scripts
Double Click on a script to add code into it so that any Game Object with the attached script has its
functionality.
Create Prefabs
Drag a Game Object from the Hierarchy Tab into Project Tab (preferably Prefab folder) to create a prefab.
Now you can create clones of this new Game Object just by dragging it to the scene.
The prefab editor allows you to make changes later on a prefab and the changes will apply to every instance of
the prefab.
Add Audio
You can add background music and sound effects to your game.
Select a Game Object like Main Camera from the hierarchy and drag Music file from Project tab to the
Inspector tab, to add an Audio Source component. Make sure that Loop and Play On Awake check boxes are
checked in Inspector tab.
ADD SFX (Sound Effects)
Select a Game Object that should play the sound effect from the hierarchy and drag Sound file from Project tab
to the Inspector tab, to add an Audio Source component. Make sure that Loop and Play On Awake check
boxes are unchecked in Inspector tab.
public AudioSource sound; // On the editor, drag the game object with the sound source into this public variable
void Start()
sound = GetComponent<AudioSource>();
sound.Play();
Add UI
UI elements like Images, Buttons, text, and various interactable elements can be added to the game, they will
be under a Canvas Game Object.
Create UI
To create a UI element, right click on Hierarchy tab, select UI, then select desired UI to create – Text, Button,
Image, etc. If a Canvas Game object already exists, the new UI element will be created as a child of the
canvas, otherwise a new Canvas game object will automatically be created.
Position UI
It is best practice to use anchors to position UI elements to cater to different display resolutions
3. then hold Alt + Shift and select with Mouse 1 desired location of UI
Useful UI elements
The following are useful UI elements you can create and use:
Text
1. Right click on Hierarchy, select UI, then Text. You can change the parameters (font, color, size, alignment,
etc.) of this new text game object in its Text (Script) component via the Inspector.
a. NOTE: If the font is too big, the text will disappear. Adjust the size of the text box using the
Rect tool (shortcut T) on the Scene view
Buttons
You can create UI buttons for different things like Start or Exit Game button
3. Under the Button (Script) component, there is an On Click () section that starts out as List is Empty. Click
the + sign to add effects of button click.
4. Drag the GameObject with a script attached to it to the newly created input field which shows None
(Object)
a.
5. Click on No Function, then select the script name on the list, then select the function you want called when
the button is clicked.
Building a Project
To build your project:
2. Click Add Open Scene button to add current scene or drag scene from Project tab to Scenes In Build.
3. Choose the Platform you want to build – PC, Android, or WebGL (web browser). If you change platform to
build then you need to click Switch Platform.
4. The 1st scene on the start of the game (e.g. Title screen or intro) should be on top of the list of Scenes in
Build.
5. When all of your desired scenes are under Scenes In Build, Click Build and Run.
Destroy
To destroy game object, Add the following script to the Game Object
Events
Events are specialized delegates useful to alert other classes that something has happened. They work
similarly to public multiclass delegates.
Delegate Event
Tutorial link -
https://www.gamasutra.com/blogs/VivekTank/20180703/321126/How_to_use_C_Events_in_Unity.php
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
{
public delegate void onMyDelegate(); //Declare a Delegate
if (onMyEvent != null)
// Note that different scripts can define different conditions for an event to trigger
void Update()
if (Input.GetKeyDown(KeyCode.P))
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScoreEvent : MonoBehaviour
EventManager.onMyEvent += ScoreFunction;
EventManager.onMyEvent -= ScoreFunction;
Debug.Log("Score");
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
if (onMyEvent != null)
a. This is what triggers the event. In this example, the conditions are – object with the script is
touched or mouse 1 clicked
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
void Update()
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (GetComponent<Collider2D>().OverlapPoint(wp))
// Event handler has the condition for event above and the following line
EventManager.EventFunction();
3. Create scripts that subscribe to the event and also triggers when the event occurs
a. In this example add score function is called when the event occurs.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public AudioSource sound; // On the editor, drag the game object with the sound source into this public variable
void Start()
ScoreText.text = ScoreVariable.ToString();
sound = GetComponent<AudioSource>();
sound.Play();
ScoreText.text = ScoreVariable.ToString();
EventManager.onMyEvent += AddScore;
EventManager.onMyEvent -= AddScore;
Instantiate
Use the following script to create a Game Object during run time.
public Transform prefab;
using UnityEngine;
using System.Collections;
void Start()
}
}
Instantiate projectiles
Syntax:
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation, Transform parent);
using UnityEngine;
using System.Collections;
void Update() {
if (Input.GetButtonDown("Fire1")) {
Rigidbody clone;
Scene Change
Tags: change map change Level Change Scene load scene load level
Use script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
SceneManager.LoadScene(nextScene);
Touch
Touch controls script
void Update()
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (GetComponent<Collider2D>().OverlapPoint(wp))
Terms
Editor – this is the Unity interface where you can create your game
Game Object – any object in the scene that has a transform and can have components
Hierarchy – this is the list of game objects that is in the game scene. Selecting a game object in the hierarchy
will display its components on the Inspector tab
UI – User Interface