Start and stop the particles
-
I'm just a beginner with Lens Studio, so this might be not work for your use case but I have typically used the behavior script (Baked in with LS2.0) for starting and stopping objects.
Comment actions -
Hi Furkan!
Eric is right, you can use the Behavior Script to help with this. To add Behavior Script:
Then select the new object, and in its Inspector panel, you can have the end of an animation trigger a function.
To create a callback to this trigger, create a script and attach it to an object.
Then in the script do something like
// -----JS CODE-----
// @input Asset.Material particleMaterial
// Listen to the behavior script event
global.behaviorSystem.addCustomTriggerResponse("play-particle", function() {
// Emit 100 particles
script.particleMaterial.mainPass.spawnMaxParticles = 100
// Stop emitting particles after 2 seconds
stopParticle.reset(2);
})
var stopParticle = script.createEvent("DelayedCallbackEvent");
stopParticle.bind(function(eventData)
{
// Stop emitting particles
script.particleMaterial.mainPass.spawnMaxParticles = 0
});In the Inspector panel, where you put the script, you can attach your particle's material to the input
To make sure the particles don't start playing when the Lens start, select the particle material and set its Particle Count Amount to 0
The last thing you need to do is tell your image to not auto-play, since we want it to only play once so we can get the animation end callback. Select the animation in the Resources panel, and then until Always Play in the Inspector panel.
To get it to play when the lens turn on, we can use the Behavior Script as well:
And that's it! Your particle should now play after the animation ends, and stop after 2 seconds. Let me know if you need any clarification!
Can't wait to see what you come up with :)
Cheers,
Jon
Comment actions
Please sign in to leave a comment.
Have a comment?