Particle System not affected by script if autodestruct is set

I’ve created a collection of particle systems for a one-shot explosion effect (includes systems for smoke, fire and sparks). They are all set to self destruct, along with the GameObject that holds them (has a script that checks if there are any particle system children).

I wrote another script for the particle systems themselves that move them a little closer to the camera, to avoid the z fighting problem when two systems spawn at the same location. Here is the script:

// inspector variables
public float layerHeight = 0.0f;

// private variables
Vector3 pos;

// Use this for initialization
void Start () {
	pos = transform.localPosition;
}

// Update is called once per frame
void Update () {
	GameObject obj = Camera.main.gameObject;

	Vector3 vec = obj.transform.position - transform.position;
	vec.x = 0;	// camera is orthographic
	vec.y = 0;

	if(transform.parent && (vec.magnitude > layerHeight || layerHeight < 0.00) )
		transform.position = transform.parent.TransformPoint(pos) + vec.normalized * layerHeight;
}

It works fine when the particle systems are not set to self destruct, but once they are, the script does not affect them at all.
Any ideas?

2 Answers

2

try using BroadcastMessage to trigger the auto destruct function.

Broadcast Message Link

I too have the same issue.I created one gun script.I created one particle sparking effct f,but it is no t working with autodestruct on.it will work continuously if its offf.
any suggestion for creating gun fire perfectly wih particle effect??