I read a thread earlier regarding what exactly the “:” does in javascript. I understand that it is used to introduce the tertiary element in a conditional and also to define arrays, but I cannot seem to get my head around what it is doing in the following code from the platformer tutorial. Thank you guys for your assistantance!
var initialRespawn : Respawn; // set this to the initial respawn point for the level.
var RespawnState = 0;
// Sound effects:
var SFXPlayerRespawn: AudioClip;
var SFXRespawnActivate: AudioClip;
var SFXRespawnActiveLoop: AudioClip;
var SFXVolume: float; // volume for one-shot sounds.
// references for the various particle emitters...
private var emitterActive: ParticleEmitter;
private var emitterInactive: ParticleEmitter;
private var emitterRespawn1: ParticleEmitter;
private var emitterRespawn2: ParticleEmitter;
private var emitterRespawn3: ParticleEmitter;
// ...and for the light:
private var respawnLight: Light;
The : is used to define the type of a variable. Some of the variables in that code are “holders” for audio clips, others particle emitters, etc.
I have to assume there is a script called “Respawn” somewhere in the project, as “Respawn” is not a standard variable type in Unity. (You can use the names of other scripts as variable types.)
Thanks Jessy!!! After posting this I did some more digging. Hopefully someone can tell me if I’m right. Is the “Respawn” line basically just pointing to an object that one would define in the editor, or is this something different?
Respawn would be another script/class. With Javascript in Unity, as a basic rule all the scripts and classes that inherit from monobehaviour. They then get added to objects in the scene as components. Respawn would be one of those scripts.
So for example if the name of the script containing the code from your initial post was named “RespawnManager”, in order to have a variable of that type you would declare it as :
var respawnMan : RespawnManager;
That variable would then allow you to access any public functions/variables in an instance of that class.