- Home /
Determine completion of Particle System without polling?
Is an event fired when the Shuriken Partical System has completed? I'd rather override an event than have to poll.
Thanks!
Answer by souperdavecdn · Feb 06, 2013 at 08:49 AM
SOLUTION - How to monitor a Particle System without polling
The Particle System's ParticleSystem.duration property set from the inspector is used for the interval in the following script. Once the time is elapsed the script messages and voila! you know your Particle System is done.
// ***************************** START Snippet Timer.js ************************************** #pragma strict
// Timer.js
// Dave Brace / souperdavecdn
// 2/6/2013
// Uses a co-routine to notify of elapsed time
// Default interval corresponds to length of animation clip
// Uses Unity Messaging
var interval :float = 2.35;
var debugOn :System.Boolean = false;
private var myNumber : int;
// Dummy for debug only
var myExNumber : int;
function _SetMyNumber(num:int){
// Set by instantiating code
myNumber = num;
myExNumber = num;
}
function _Start(){
if(debugOn){
print (transform.name + ": Starting " + Time.time);
}
yield WaitUntilInterval();
}
function WaitUntilInterval() {
// suspend execution for interval seconds
yield WaitForSeconds (interval);
if(debugOn){
print (transform.name + ": Completed "+ Time.time);
}
_OnCompleted();
}
function _OnCompleted(){
SendMessageUpwards("_ItemAvail",myNumber,SendMessageOptions.DontRequireReceiver);
}
// ***************************** END Timer.js **************************************
Your answer
Follow this Question
Related Questions
Particle system ends with shuriken graphic 1 Answer
Make UI Particle System not scale 0 Answers
Particle System Renderer mode is breaking Texture Sheet Animation 1 Answer
How to pause emitter in new Particle System? 2 Answers
Why are all the particles in my particle system disappearing when it's off screen? 1 Answer