Weird behaiviour with particle system.

I have a very simple script that when “isMoving” is checked should;

  • start moving the object left
  • play the particle system

however, lol…what is happening instead baffles me.

The object will move but the particle system does not play until…

I unchecked “isMoving”. At that point, the object obviously stops moving and then the particle system kicks in! It’s completely backwards!

#pragma strict

var speed: 		float = 05;

var myEffect: 	ParticleSystem;
var isMoving:	boolean = false;

function Start ()
{
	myEffect.Stop ();
}

function Update ()
{
	if (isMoving)
	{	
		Rolling ();
	}
}

function Rolling ()
{
	myEffect.Play ();
	transform.Translate(Vector3.left * Time.deltaTime * speed );
	yield;
}

What’s going on here is that you are continuously calling the particle system to start itself. But as you do this you also reset the particle system, so you are practically constantly resetting it which results in no visualization.

What you can do about this is check if your particle system is already playing before you ask it to play, like so:

if (!myEffect.isPlaying)
    myEffect.Play ();