How do I pause ONLY c# script but not objects/effects?

Objective 1: speed. No instantiates/destroys (memory management/garbage collection is slow!)
Objective 2: particle effects continue to play, and in-place.
Objective 3: after effect/pause has ended, continue to run script.

Scenario: Object has attached particle effect that is tripped by event, and event results in deactivation of this.object’s rendering and eventual relocation of this.object. Desire is for the effect to be seen in full at this.object’s current location before it is moved. However, the only way I’ve found for this to occur is to use Destroy(object) with a timed delay; moving this.object causes the effect to move with it, even though “global” space has been checked in the particle effect options. The object then must be Instantiated from the prefab (with attached effect disabled) upon next use. With over 500 of the same object being constantly Destroyed and Instantiated, cleanup slows things down considerably! But my attempts at recycling the objects through simply {renderer.enabled=false; pause(){yield WaitForSeconds(x);} transform.position} have hit {this.snag} !LOL with the particle system… any ideas? :slight_smile:

Rather than Destroy(), couldn't you just turn the renderer off on the object then move and re-enable the renderer when the effect is done? Or alternately, could you put the particle effect on a child object, and either change the local position of the child object to keep it at the same position when the parent moves setting the localPosition to (0,0,0) when the effect is done, or breaking the parent/child relationship during the playing of the effect and then reestablishing it after playing?

GameObject.Find("LevelNo").GetComponent<scriptname>().enabled=false;

Hmmm... as solutions seem scarce, I've worked around the problem (though not eliminated it) by having an v.Update check for ParticleSystem.isPlaying. Still using processor I'd rather devote to something else, and had to create a "buffer" of objects to compensate for realistically inactive objects in play during the wait cycle... but it's functional. Thanks all for your views and thoughts :)

1 Answer

1

Try

bool disableScript;
public scriptYouWantToStop scriptYouWantToStop;

void Update
{
    if(disableScript)
    {
        scriptYouWantToStop.enabled = false;
    }else {
        scriptYouWantToStop.enabled = true;
    }
}`

This is untested code, just drag the script you want to stop into the “scriptYouWantToStop” variable in the inspector.

That is an example of how to pause a script. I think you should follow robertbu’s advice though and disable the mesh renderer.