3. What about?
“Unity is a game development ecosystem: a
powerful rendering engine fully integrated with a
complete set of intuitive tools and rapid workflows to
create interactive 3D and 2D content; easy
multiplatform publishing; thousands of quality,
ready-made assets in the Asset Store and a
knowledge-sharing community.”
http://unity3d.com/unity
4. Tell me more…
Components
- Game engine: 3D
objects, lighting,
physics, animation,
scripting
- 3D terrain editor
- 3D object animation
manager
- GUI system
- MonoDevelop:
code editor
(win/mac), Can
also use Visual
Studio (Windows)
Executable
exporter many
platforms:
Android/iOS
Pc/Mac
Ps3/Xbox
Web/flash
Unity 3D Asset Store:
There you can find all
assets you want, also
for free.
6. Scene & Game
The Game window shows you what
your players will see on click on Play
button.
The Scene window is where you can
position your Game Objects and
move things around. This window has
various controls to change its level of
detail.
7. Project & Hierarchy
It lists all of the
elements that you'll
use to create Game
Objects in your
project
The Hierarchy
panel lists all of
the Game Objects
in your Scene.
Game Objects for
example cameras,
lights, models, and
prefabs
Unity will
automatically detect
files as they are
added to your
Project folder's
Assets folder.
8. Inspector
The Inspector is a context-sensitive panel, which means that it
changes depending on what you select elsewhere in Unity. This
is where you can adjust the position, rotation, and scale of
Game Objects listed in the Hierarchy panel.
Game Objects can be grouped into layers, much like in
Photoshop or Flash. Unity stores a few commonly used layouts
in the Layout dropdown. You can also save and load your own
custom layouts.
9. 1- Download “space” texture.
2- Create > Material “background”
3- Associate “space” to ”background”
4- GameObject > Create Other > Plane
5- Set -90 X plane’s rotation
6- Change shader from “diffuse” to
“background”
7- Set “background” tiling a 8,8 (X,Y)
8- Save Scene (Ctrl+s)
Start: Scene
10. 1- GameObject > Create Empty
“SpaceInvader”
2- Set -2 Z Position
3- Create Material for “SpaceInvader “ and set
shader in Mobile > Transparent >
Vertex Color
4- GameObject > Create Other > Quad
“Spaceship” (simple plane composted by 2
triangle)
5- Associate “Spaceship” to material of
“SpaceInvader” that now it contain the quad.
Enimies
12. Let’s Script!
using UnityEngine;
using System.Collections;
public class EnemyController : MonoBehaviour
{
public float speed;
void Start () {
}
void Update () {
this.transform.position -= new Vector3(speed, 0, 0) * Time.deltaTime;
}
}
Create > C# Script “EnemyController ” and associate “EnemyControlle” to “SpaceInvader”
13. Prefab
- Since object-oriented instances can be INSTANTIATED at run time.
- Unity uses the term PREFAB for a pre-fabricated object template (i.e. a class combining 3D
objects and scripts)
- At DESIGN TIME (in editor) a prefab can be dragged from Project window into the Scene window
and added the scene’s hierarchy of game objects. The object can then be edited (i.e. customised
from the prefab default settings) if desired
- At RUN TIME a script can cause a new object instance to be created (instantiated) at a given
location / with a given transform set of properties
For transform a
GameObject in a
Prefab: Drag&Drop the
GameObject into a
folder “Prefabs”
created precedently in
the Project View.
14. 1- GameObject > Create Empty “Laser” to trasform in Prefab and set -2 Z
Position
2- Create Material for Laser and set shader in Mobile > Particles/Additive
3- GameObject > Create Other > Quad “LaserBody” and associete to “Laser”
4- Associate material “Laser” to “LaserBody” and set his properties Position =
(0,0,0), Rotation = (0,0,0), Scale = (0.5, 0.05, 1).
5- Create the Script for his comportament.
Laser
using UnityEngine;
using System.Collections;
public class LaserController : MonoBehaviour{
void Start () {}
void Update () {
this.transform.position += new Vector3(10, 0, 0) * Time.deltaTime;
if (this.transform.position.x > 20.0f) {
Destroy(this.gameObject); // if not, they run to infinite
}
}
}
15. Let’s Script.. again!
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour
{
public GameObject enemy;
public GameObject laser;
float spawnTimer;
void Start() {
spawnTimer = 1.0f;
}
void Update () {
spawnTimer -= Time.deltaTime;
if (spawnTimer <= 0.0f) {
GameObject instance = (GameObject) Instantiate(enemy, new Vector3(10, Random.Range(-.0f,4.0f), -
2.0f), transform.rotation);
spawnTimer = 1.0f;
}
}
}
Create > C# Script “GameController ” for they let are appare more enemies random in the
game and associate the script to Main Camera Object and the prefabs to his public variables.
16. using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour {
public GameObject enemy;
public GameObject laser;
float spawnTimer;
float shootTimer;
void Start () {
spawnTimer = 1.0f;
}
void Update () {
spawnTimer -= Time.deltaTime;
shootTimer -= Time.deltaTime;
if (spawnTimer <= 0.0f) {
GameObject instance = (GameObject)Instantiate(enemy,
new Vector3(10,Random.Range(-4.0f,4.0f),-2.0f), transform.rotation);
spawnTimer = 1.0f;
}
if (shootTimer <= 0.0f) {
if (Input.GetButton("Fire1")) {
Vector3 spawnLaserPos = Camera.main.ScreenToWorldPoint(
new Vector3(-5.0f, Input.mousePosition.y,8));
Instantiate(laser, spawnLaserPos, Quaternion.identity);
shootTimer = 0.4f;
}
}
}
}
1- Edit > Project Settings >
Input
2- Edit “left ctrl” to “space”
3- Edit the script “GameController ”
And again!
17. 1- Add a new Tag in inspector of Prefabs Laser for “Laser” and Enemy for “Enemy”
2- In the Tags & Layers panel add tags Laser and Enemy and assign the Tags to the Prefabs.
4- In the Prefabs’s inspector, add a BOX COLLIDER 2D and set size(0.5, 0.05, 1)
5- Add new component on the Prefabs: Rigidbody and deflag Gravity .
Collision!
18. using UnityEngine;
using System.Collections;
public class EnemyController : MonoBehaviour{
public float speed;
void Start () {}
void OnCollisionEnter(Collision other) { //unity method
if (other.gameObject.tag.Equals("Laser")) {
Destroy(other.gameObject);
Destroy(this.gameObject);
Instantiate(explosion, this.transform.position, this.transform.rotation);
}
}
void Update () {
this.transform.position -= new Vector3(speed, 0, 0) * Time.deltaTime;
}
}
1- GameObject > Create Empty “Explosion” to trasform in Prefab
2- Edit Script “EnemyController ” for the Collision and Explosion
3- Associate prefab “Explosion” to “SpaceInvader” Prefab
Script…again!
19. When: Enemies touch left boorder line.
1- File > New Scene “GameOver”
2- GameObject > Create other > GUI Text and set
Position (0.5,0.5,0).
3- Set black the Main Camera background
4- Return with duble click to gameScene, File gt;
Build Settings: for add the scene GameOver to the
project
5- Add the two scenes with Add Current
GAME OVER
20. using UnityEngine;
using System.Collections;
public class EnemyController : MonoBehaviour{
public float speed;
void Start () {}
void OnCollisionEnter(Collision other) { //unity method
if (other.gameObject.tag.Equals("Laser")) {
Destroy(other.gameObject);
Destroy(this.gameObject);
Instantiate(explosion, this.transform.position, this.transform.rotation);
}
}
void Update () {
this.transform.position -= new Vector3(speed, 0, 0) * Time.deltaTime;
if (this.transform.position.x <= -10.0f) {
GameOver();
}
}
void GameOver(){ Application.LoadLevel(1); } //change scene
}
Script…again!
21. using UnityEngine;
using System.Collections;
public class GameOverController : MonoBehaviour{
float gameOverTimer;
void Start () {
gameOverTimer = 5.0f;
}
void Update () {
gameOverTimer -= Time.deltaTime;
if(gameOverTimer <= 0.0f)
Application.LoadLevel(0);
}
}
Return to Game!
Create > C# Script “GameOverController ” and associate the script to GameOver Scene’s
Main Camera