Hi guys, the problem I’m having within my script is that I need to be able to detect when a particle emitter should activate and when it does remove a certain amount of points from the score.
Now, it does activate the emitter and also DOES remove points from the score, the problem is that due to it having to be within the “function Update” it’s removing points every frame which results in the score being drastically reduced.
What I want to know is if there’s anyway I can make it so that it will only be called the one time or if there’s a possible workaround for the problem.
Code is below:
var Beep : AudioClip;
public var wheelFL : WheelCollider;
public var fire : ParticleEmitter;
public var explosion : ParticleEmitter;
private var lastMovementTime : float = Mathf.Infinity;
function Start()
{
fire.emit = false;
lastMovementTime = Time.time;
}
function Update ()
{
if (wheelFL.rpm > 0.2)
{
lastMovementTime = Time.time;
}
else
{
if ((Time.time - lastMovementTime) > 5)
{
audio.PlayOneShot(Beep);
//flash_headlights();
}
if ((Time.time - lastMovementTime) > 9)
{
onFire();
}
}
if ((fire.emit == true) && (Time.time - lastMovementTime > 19))
{
explode();
}
}
function onFire()
{
fire.emit = true;
StatisticsScript.scorePoints -= 5;
}
function explode()
{
explosion.emit = true;
yield WaitForSeconds (3.0);
Destroy (gameObject);
StatisticsScript.scorePoints -= 10;
}
Thanks guys, any help will be greatly appreciated.
if ((fire.emit == true) && (Time.time - lastMovementTime > 19)) { lastMovementTime = Time.time; explode(); }
– meat5000