Game Development Reference
In-Depth Information
Renderer
Click to bring the drop-down menu
Material
Smoke
8. Next, we will create a script to control our Explosion particle. Let's go to Assets |
Create | Javascript (for Unity JavaScript users) or Assets | Create | C# (for C#
users), name it AutoDestroyParticle , double-click on it to launch
MonoDevelop , and define the variables and functions as follows:
// Unity JavaScript user:
#pragma strict
var timeOut : float = 4.0f;
private var _light : Light;
private var _decreaseTime : float;
private var _isRemoveLight : boolean = false;
function Awake () {
_light = GetComponentInChildren.<Light>();
}
function Start () {
_decreaseTime = _light.range/timeOut;
Invoke("KillObject", timeOut);
}
function Update () {
if (!_isRemoveLight) {
if (_light.range > 0) {
_light.range -= _decreaseTime*Time.deltaTime;
} else {
_isRemoveLight = true;
GameObject.Destroy(_light);
}
}
}
Search WWH ::




Custom Search