@Ian094 Time.timeScale = 0 makes cloth go crazy. lol
@crag That didn’t exactly work…
After using Debug.Log, it turned out that the game paused, then immediately unpaused the game, making it seemed like nothing happened. I needed to add else if
Sometimes being a bit more specific in code helps:
function Update() {
Pause();
}
function Pause() {
if(Input.GetButtonDown("Pause") && !isPaused){
Time.timeScale = 0.0000001;
isPaused = true;
Debug.Log("Paused!");
}
else if(Input.GetButtonDown("Pause") && isPaused){
Time.timeScale = 1.0;
isPaused = false;
Debug.Log("UnPaused");
}
}
I might be asking for much, but I ran into another problem with this. @Troas I learned a lot from the link and will be a bit more careful of what is using time so they can be paused or not. My player runs on a custom platforming controller script and when I pause the game, he stops in mid air when jumping because the gravity is controlled by Time:
moveDirection.y -= gravity * Time.deltaTime * 2;
However, the rotation is still applied ONLY when I’m using my game controller, not when I use my keys. Weird…
forward = Camera.main.transform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
right = Vector3(forward.z,0,-forward.x);
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
var XZmoveDirection:Vector3 = (h * right + v * forward);
XZmoveDirection *= moveSpeed;
moveDirection.x = XZmoveDirection.x;
moveDirection.z = XZmoveDirection.z;
if(XZmoveDirection != Vector3.zero){
var rotation0 = transform.rotation;
rotation0.SetLookRotation(new Vector3(moveDirection.x,0,moveDirection.z) * rotateSpeed);
transform.localRotation = rotation0;
}
controller.Move(moveDirection * Time.deltaTime);
And finally, I have this in my Health Script, when I pause, the player respawns to the spawnpoint. Any clue about that?
function FixedUpdate(){
//Debug.Log(healthPercent);
if(healthPercent > 100){
healthPercent = 100;
}
if(healthPercent <= 0){
healthPercent = 100;
if(reSpawn){
transform.position = spawnPoint.position;
}
}
}
Thanks for the help so far and in advance! 