0

I have a particle system explosion that I want to play when the player dies. The idea that is that everything else pauses but the explosion continues, like the Pacman animation when you die (everything freezes and the pacman death animation plays).

Trouble is, it won't work. I know Time.timeScale = 0 pauses everything, and I've tried using this script to combat that, but it doesn't seem to be working:

void Update()
 {
     if (Time.timeScale < 0.01f)
     {
         particleSystem.Simulate(Time.deltaTime, true, false);
     }
 }

I have also tried this, but it doesn't work either:

 private ParticleSystem pSystem;

 public void Awake()
 {
     pSystem = gameObject.GetComponent<ParticleSystem>();
 }

 public void Play()
 {
     pSystem.Simulate(Time.unscaledDeltaTime,true,true);
 }

 public void Update()
 {
     pSystem.Simulate(Time.unscaledDeltaTime,true,false);
 }

I have tried this code with a script that is attached to my explosion particle system prefab, which is instantiated at the player's position when you die.

Thanks!

UPDATE: Turns out I had tried using particleSystem.Simulate(Time.unscaledDeltaTime, true, false);, but I was calling it in FixedUpdate() rather than Update().

However, the Asteroid Base post below posted by Garfty is really interesting and is probably worth doing in the long run!

Tom
  • 2,372
  • 4
  • 25
  • 45

1 Answers1

1

One way you could do it is by using Time.unscaledDeltaTime

Another way you could approach something like this is by creating your own time manager, but it requires some discipline to stick to. The people at Asteroid Base wrote a nice article on something like this here.

I hope this helps!

Motonstron
  • 876
  • 6
  • 10
  • This looks helpful, I will try it out later! One thing I was wondering is that, at the moment, I pause 3 things when I set Timescale to 0. Would it be easier to follow the Asteroid Base technique or do you think it would be easier to pause each individual component instead? – Tom Sep 08 '15 at 10:36
  • 1
    It completely depends on what you're trying to achieve, I personally like the Asteroid Base approach because it gives a lot of flexibility, but as mentioned it does require some discipline to use it. Try out both and see which works for you :) – Motonstron Sep 08 '15 at 20:43
  • Gave it a try, and although it was a little confusing, it works! Thanks! – Tom Sep 09 '15 at 18:49