Game Development Reference
In-Depth Information
var hallwayBaked : GameObject;
var hallwayDark : GameObject;
var flashLight : GameObject;
var gunSpark : GameObject;
var brokenCamera : GameObject;
var gunshotSoundSource : GameObject;
var switchSoundSource : GameObject;
var empGhost : GameObject;
var empReal : GameObject;
private var placingEMP : GameObject;
private var placedEMP : GameObject;
var gunshotSound : AudioClip;
var pistolActive : boolean;
var empActive : boolean;
var empGhostActive : boolean;
Why?
We could make this new variable public, but nothing but this script ever
sees it or ever needs to access it. Keeping it private keeps the Unity Editor
space from getting cluttered and helps future users of the scene not feel
like they need to populate it.
Step 11: Check to see if empActive is true, and if it is, start doing things
(that we haven't defined yet). Do this at the end (but still within) the
function Update block of code (since we want this to be happening
every frame).
if (empActive){
}
Why?
This seems like a bit of empty code, and indeed it is. It says, “check to
see if empActive is true and if it is, do nothing.” It's a trick I learned from
our team's hard-core software developer. What he does is every time he
creates a function or an if statement, he creates the start { and end } right
from the beginning, and then fills in the middle. It helps him keep track of
all the opening and closing brackets.
Step 12: Have the script instantiate empGhost only if empGhostActive
(the Boolean) is not true, and then once the object is instantiated, set
empGhostActive to be true:
Search WWH ::




Custom Search