Hi everybody!
I recently set up a script to destroy a cube, when destroyed a particle effect will appear… This all happens when the ‘Player’ enters its box collider.
The problem I’m having is that when I press Play the sound file that I set up for the cube plays straight away, and when the Player walks at the box the sound file doesn’t play but the particle effect is still happening.
The code I’m using aint showing any errors… But im thinking I could have it set up wrong… Suggestions are welcome! =]
#pragma strict
var Boom : ParticleEmitter;
var onlyPlayOnce : boolean = true;
RequireComponent (AudioSource);
function OnTriggerEnter (collision : Collider) {
if (collision.gameObject.name == "Player")
{
Instantiate(Boom, transform.position, transform.rotation);
Destroy(gameObject);
}
}
private var playedOnce : boolean = false;
function OnTriggerEnter () {
if (playedOnce && onlyPlayOnce)
return;
audio.Play ();
playedOnce = true;
}