|
Hi there, As means of explaining my scene, I have two cubes (cube1 and cube2), a fountain particle system and audio for it. Cube1 is a trigger to allow cube2 to work, so cube2 will only trigger the fountain AFTER cube1 has been collided with, even if you walk into cube2 prior. This works very well but the audio plays whenever you collide with cube2. Am I able to do something similar to the particles? Can I script the audio to only start once you collide with cube2 only after you have collided with cube1?? Hope this makes sense, my code is: Code for Trigger2:
(comments are locked)
|
|
If the audio is a loop (as fountain sounds usually are), you can Play the audio when start emitting particles, and Stop it when finishing emitting:
...
function OnTriggerEnter(trigger: Collider){
if (enable){
fountain.particleEmitter.emit = true;
fountain.audio.Play();
splash.particleEmitter.emit = true;
splash.audio.Play();
}
}
function OnTriggerExit(trigger:Collider){
if (enable){
yield WaitForSeconds(2);
fountain.particleEmitter.emit = false;
fountain.audio.Stop();
yield WaitForSeconds(2);
splash.particleEmitter.emit = false;
splash.audio.Stop();
}
}
...
Once again Aldo you make it look so easy!! Thank you very much :) Done and Done
May 26 '12 at 11:41 PM
mcfetrmatt
(comments are locked)
|

Do yourself a favor, do not use SendMessage(). Here's a quick reason: http://forum.unity3d.com/threads/38094-Is-SendMessage-really-that-bad?p=245838&viewfull=1#post245838
From the same post, "Optimization is not about avoiding expensive code. It's about avoiding expensive code where it matters". This code will be called infrequently, thus the perfomance gain using GetComponent is negligible.