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
}
}