How to pause only specific objects/prefabs?

I would like to be able to pause my game via script, but leave specific prefabs (in this case my camera) not paused and moving as per normal. Here is the scenario:

When my character gets a certain distance from an enemy I would like to be able to pause my game (for a specified time) BUT not pause my camera so that it can turn towards the enemy while everything else is paused. I’ve been looking at Time.timescale and using it for the “pause” functionality but I don’t know how to pause everything except the camera. Would something like this be possible?

I think you should use time.fixedDeltaTime instead of time.deltaTime, that makes the prefab ignore the timescale==0. I’m only a beginner and this happened to me once, I hope I helped.

You could use a custom Update function on everything that need an Update and can be paused, something like :

public abstract class MonoPause : MonoBehaviour // Any resemblance to lady stuff is purely coincidental ...
{
	public bool pause = false;
	
	private IEnumerator Start()
	{
		while( Application.IsPlaying )
		{
			if( !pause )
				DoUpdate();
				
			yield return null;
			
			// You could even have a time variable here
		}
	}
	
	// That's where it happens !
	protected abstract void DoUpdate();
}

and …

public class Pouet : MonoPause
{
	protected override void DoUpdate()
	{
		// Movement and stuff
	}
}

@Hamesh81
@wowza
@Berenger

hello i am writing an RTS i wanted to be able to pause only the scene not the camera.

i have a time manager script were i can set the time scale to zero which is perfect. however it paused the camera as well.

when you set time scale to 0 fixedupdate is never called on all monevelopements

  • all of my input for the camera was in the fixed update
  • all smoothing was done by using time.deltatime

to make the camera move independent of the time scale i changed the fixedupdate to lateupdate.

then instead of using time.deltatime for smoothing the input i used time.unscaledDeltaTime

using unscaled delta time also allows you to x2, x10 the scenes scale and keep the camera’s movement seperate.