SlideShare a Scribd company logo
Roma 2014
Google DevFest
Presented by
Vincenzo Favara
vin.favara@gmail.com
www.linkedin.com/pub/vincenzo-favara/2b/117/355
www.google.com/+VincenzoFavaraPlus
Who am I?
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
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.
GUI
1. Scene
2. Hierarchy
3. Inspector
4. Game
5. Project
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.
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.
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.
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
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
Decorator
1- Asset > Import
Package > Particles
2- Associate “Smoke Trail”
to “SpaceShip”
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”
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.
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
}
}
}
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.
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!
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!
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!
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
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!
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
“It will work”!
“Could it work”?
The Impossible is
the first step towards
possible
(cit. by me)

More Related Content

What's hot (20)

PDF
Sequence diagrams
Alfonso Torres
 
PDF
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
PPTX
Building a turn-based game prototype using ECS - Unite Copenhagen 2019
Unity Technologies
 
PDF
libGDX: Tiled Maps
Jussi Pohjolainen
 
ODP
Locally run a FIWARE Lab Instance In another Hypervisors
José Ignacio Carretero Guarde
 
PPTX
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
Unity Technologies
 
PDF
The Ring programming language version 1.5.2 book - Part 49 of 181
Mahmoud Samir Fayed
 
PDF
Converting Scene Data to DOTS – Unite Copenhagen 2019
Unity Technologies
 
PPTX
Game dev 101 part 3
Christoffer Noring
 
PDF
Intro to Asha UI
Jussi Pohjolainen
 
PDF
The Ring programming language version 1.8 book - Part 56 of 202
Mahmoud Samir Fayed
 
PDF
UIImageView vs Metal [日本語版] #tryswiftconf
Shuichi Tsutsumi
 
PDF
The Ring programming language version 1.6 book - Part 52 of 189
Mahmoud Samir Fayed
 
PPTX
Cross platform game development
Jerel Hass
 
PDF
The Ring programming language version 1.5.1 book - Part 48 of 180
Mahmoud Samir Fayed
 
PDF
3D Computer Graphics with Python
Martin Christen
 
PDF
Enhance your world with ARKit. UA Mobile 2017.
UA Mobile
 
PDF
Snapshot clone-boot-presentation-final
Open Stack
 
PDF
How I hacked the Google Daydream controller
Matteo Pisani
 
PDF
Custom SRP and graphics workflows - Unite Copenhagen 2019
Unity Technologies
 
Sequence diagrams
Alfonso Torres
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
Building a turn-based game prototype using ECS - Unite Copenhagen 2019
Unity Technologies
 
libGDX: Tiled Maps
Jussi Pohjolainen
 
Locally run a FIWARE Lab Instance In another Hypervisors
José Ignacio Carretero Guarde
 
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
Unity Technologies
 
The Ring programming language version 1.5.2 book - Part 49 of 181
Mahmoud Samir Fayed
 
Converting Scene Data to DOTS – Unite Copenhagen 2019
Unity Technologies
 
Game dev 101 part 3
Christoffer Noring
 
Intro to Asha UI
Jussi Pohjolainen
 
The Ring programming language version 1.8 book - Part 56 of 202
Mahmoud Samir Fayed
 
UIImageView vs Metal [日本語版] #tryswiftconf
Shuichi Tsutsumi
 
The Ring programming language version 1.6 book - Part 52 of 189
Mahmoud Samir Fayed
 
Cross platform game development
Jerel Hass
 
The Ring programming language version 1.5.1 book - Part 48 of 180
Mahmoud Samir Fayed
 
3D Computer Graphics with Python
Martin Christen
 
Enhance your world with ARKit. UA Mobile 2017.
UA Mobile
 
Snapshot clone-boot-presentation-final
Open Stack
 
How I hacked the Google Daydream controller
Matteo Pisani
 
Custom SRP and graphics workflows - Unite Copenhagen 2019
Unity Technologies
 

Similar to Unity3 d devfest-2014 (20)

PDF
Laser Defender Game in Unity3D
CompleteUnityDeveloper
 
PDF
School For Games 2015 - Unity Engine Basics
Nick Pruehs
 
PDF
Introduction to Unity by Purdue university
asdf936939
 
PDF
Developing VR Experiences with Unity
Mark Billinghurst
 
PDF
Mobile AR Lecture6 - Introduction to Unity 3D
Mark Billinghurst
 
PPTX
Introduction to Unity
University of Auckland
 
PPTX
Creating great Unity games for Windows 10 - Part 1
Jiri Danihelka
 
PPTX
Unity workshop
fsxflyer789Productio
 
PDF
Cardboard VR: Building Low Cost VR Experiences
Mark Billinghurst
 
PDF
An Introduction to the Unity GamingEngine
Stevexm1
 
PDF
Presentación Unity
Laura Milena Parra Navarro
 
PPTX
unity gaming programing basics for students ppt
KathiriyaParthiv
 
PDF
How tomakea gameinunity3d
Dao Tung
 
PPTX
Academy PRO: Unity 3D. Environment
Binary Studio
 
PPTX
Game Project / Working with Unity
Petri Lankoski
 
PDF
3 d platformtutorial unity
unityshare
 
PDF
Unity 101
Hibby Games
 
PDF
The Basics of Unity - The Game Engine
OrisysIndia
 
PDF
Building VR Applications For Google Cardboard
Mark Billinghurst
 
PPTX
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
Laser Defender Game in Unity3D
CompleteUnityDeveloper
 
School For Games 2015 - Unity Engine Basics
Nick Pruehs
 
Introduction to Unity by Purdue university
asdf936939
 
Developing VR Experiences with Unity
Mark Billinghurst
 
Mobile AR Lecture6 - Introduction to Unity 3D
Mark Billinghurst
 
Introduction to Unity
University of Auckland
 
Creating great Unity games for Windows 10 - Part 1
Jiri Danihelka
 
Unity workshop
fsxflyer789Productio
 
Cardboard VR: Building Low Cost VR Experiences
Mark Billinghurst
 
An Introduction to the Unity GamingEngine
Stevexm1
 
Presentación Unity
Laura Milena Parra Navarro
 
unity gaming programing basics for students ppt
KathiriyaParthiv
 
How tomakea gameinunity3d
Dao Tung
 
Academy PRO: Unity 3D. Environment
Binary Studio
 
Game Project / Working with Unity
Petri Lankoski
 
3 d platformtutorial unity
unityshare
 
Unity 101
Hibby Games
 
The Basics of Unity - The Game Engine
OrisysIndia
 
Building VR Applications For Google Cardboard
Mark Billinghurst
 
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
Ad

Recently uploaded (20)

PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Ad

Unity3 d devfest-2014

  • 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.
  • 5. GUI 1. Scene 2. Hierarchy 3. Inspector 4. Game 5. Project
  • 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
  • 11. Decorator 1- Asset > Import Package > Particles 2- Associate “Smoke Trail” to “SpaceShip”
  • 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
  • 23. The Impossible is the first step towards possible (cit. by me)