playMaker

Author Topic: Particle On Off  (Read 11907 times)

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Particle On Off
« on: August 15, 2011, 07:52:06 AM »
Here is a little Action i made to turn on and off a particle system... I have since read and managed to get working the Auto Destroy function which would have worked for me at the time.. But i made this instead. And then removed my particle system anyway.

For the delay i used the Wait Action as a template so if that is a bad way to do that then maybe someone else has a better way. But it seemed to work fine.

This Action will work as a basic switch with no Delay Value set or  as a Delayed Toggle if you set a Delay value.. So you can either Toggle it on then off or the other way around

Q

Code: [Select]

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Turns a Particle Emitter on and off with optional delay.")]
public class particleEmitterOnOff : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[Tooltip("Set to True to turn it on and False to turn it off.")]
public FsmBool emitOnOff;
[Tooltip("If 0 it just acts like a switch. Values cause it to Toggle value after delay time (sec).")]
public FsmFloat delay;
public FsmEvent finishEvent;
public bool realTime;

private float startTime;
private float timer;
private GameObject go;

public override void Reset()
{
gameObject = null;
emitOnOff = false;
delay = 0f;
finishEvent = null;
realTime = false;
go = null;
}

public override void OnEnter()
{
go = Fsm.GetOwnerDefaultTarget(gameObject);
go.particleEmitter.emit = emitOnOff.Value;

if (delay.Value <= 0)
{
Finish();
return;
}

startTime = Time.realtimeSinceStartup;
timer = 0f;
}

public override void OnUpdate()
{
// update time

if (realTime)
{
timer = Time.realtimeSinceStartup - startTime;
}
else
{
timer += Time.deltaTime;
}

if (timer > delay.Value){
go.particleEmitter.emit = !emitOnOff.Value;
Finish();
if(finishEvent != null) Fsm.Event(finishEvent);
}
}

}
}

FractalCore

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 98
    • View Profile
Re: Particle On Off
« Reply #1 on: January 04, 2012, 08:39:35 PM »
I still find this action very useful, thanks. However it doesn't seem to work with the new particle system in Unity 3.5. Not surprising since it's so different now. I don't supposed an updated version would be possible would it?

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Re: Particle On Off
« Reply #2 on: January 05, 2012, 09:19:12 PM »
Well i am sure that would be possible. I have not bothered with 3.5 as i am in the middle of a big project so no time for messing with beta software. I am sure someone could update it for you or i can when i get into 3.5

Q

FractalCore

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 98
    • View Profile
Re: Particle On Off
« Reply #3 on: January 08, 2012, 02:16:41 AM »
That's cool, no rush. I just wanted to point it out so it's known. To be honest the new particle system hasn't grown on me yet. So I don't mind using the old one still.

FractalCore

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 98
    • View Profile
Re: Particle On Off
« Reply #4 on: January 19, 2012, 03:02:28 AM »
Was just poking around with Set Property and it works on the new Particle System. It allows you to set an Enable Emission Bool for turning it on and off. Awesome.

Pikamus

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Particle On Off
« Reply #5 on: April 19, 2012, 11:03:33 PM »
FractalCore just wondering how you done this? can you explain.
i'm trying to do the same thing!
thank you for your help

FractalCore

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 98
    • View Profile
Re: Particle On Off
« Reply #6 on: April 19, 2012, 11:43:03 PM »
Happy to...

In this example I'm adding Playmaker Actions to the particle system itself. But that's not necessary. The way this is set up, pressing space will toggle the particles emitting on/off. That's what the Bool is for, unticked is off, ticked is on.

The first picture highlights the component label you have to drag and drop on to the Set Property part you see in the last image where it says Particle System. Then you get the options specific to it.

Hopefully the pictures can explain it. Let me know if you need more info.

There's a quirk where if you want to assign a component from one object to a Playmaker FSM assigned to another, you have to turn on Lock so you don't deselect it in the process. This is why for this example I put the FSM on the Particle System itself.

Pikamus

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Particle On Off
« Reply #7 on: April 28, 2012, 11:59:35 PM »
Thanks Fractal Core,
Works like a charm
^_^

justifun

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 231
    • View Profile
Re: Particle On Off
« Reply #8 on: April 30, 2012, 12:39:38 PM »
Has anyone had an issue with dragging a component from an object prefab that's not on your current prefab?

eg: a character accessing a treasure chest's component?

MrMitch

  • Full Member
  • ***
  • Posts: 131
    • View Profile
    • Rage Quit Games - Coming Soon
Re: Particle On Off
« Reply #9 on: September 20, 2012, 03:37:01 PM »
Thanks for this it still works without any issues :)

ZeroSigma

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Particle On Off
« Reply #10 on: November 30, 2012, 03:33:14 AM »
Thanks for this script, I was looking for it.

Here is an updated version seeing as 'particleEmitter' has been depreciated.
Please feel free to modify as needed but remember to share. ;)

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Turns a Particle Emitter on and off with optional delay.")]
public class particleEmitterOnOff : FsmStateAction
{
[RequiredField]
[Tooltip("The particle system component owner.")]
public FsmOwnerDefault gameObject;
[Tooltip("Set to True to turn it on and False to turn it off.")]
public FsmBool emitOnOff;
[Tooltip("If 0 it just acts like a switch. Values cause it to Toggle value after delay time (sec).")]
public FsmFloat delay;
[Tooltip("The event is fired after the delay has been reached. NOTE: only works when delay > 0")]
public FsmEvent finishEvent;
public bool realTime;

private float startTime;
private float timer;
private ParticleSystem ps;
private GameObject go;

public override void Reset()
{
gameObject = null;
emitOnOff = false;
delay = 0f;
finishEvent = null;
realTime = false;
ps = null;
}

public override void OnEnter()
{
ps = Fsm.GetOwnerDefaultTarget(gameObject).GetComponent<ParticleSystem>();

if (emitOnOff.Value) ps.Play(); else ps.Stop();

if (delay.Value <= 0)
{
Finish();
return;
}

startTime = Time.realtimeSinceStartup;
timer = 0f;
}

public override void OnUpdate()
{
// update time

if (realTime)
{
timer = Time.realtimeSinceStartup - startTime;
}
else
{
timer += Time.deltaTime;
}

if (timer > delay.Value)
{
if (!emitOnOff.Value) ps.Play(); else ps.Stop();

Finish();
if(finishEvent != null) Fsm.Event(finishEvent);
}
}

}
}

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Particle On Off
« Reply #11 on: November 02, 2015, 07:47:38 AM »
+1 add to ecosystem

 :P

Headtrip

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Re: Particle On Off
« Reply #12 on: October 30, 2016, 10:32:23 PM »
Thanks!!! this works perfectly