as the title suggests, is there a way to make my player move when the timeScale is set to 0?
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public CharacterController controller;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask whatIsGround;
public float speed;
public float gravity = -9.81f;
public float jumpHeight;
public bool canDoubleJump = false;
Vector3 velocity;
bool isOnGround;
bool timeStopped = false;
void stopTime()
{
if (timeStopped)
Time.timeScale = 1;
else
Time.timeScale = 0;
timeStopped = !timeStopped;
}
// I want to be able to use the code in update function while Time.timeScale is set to 0.
void Update()
{
isOnGround = Physics.CheckSphere(groundCheck.position, groundDistance, whatIsGround);
if (isOnGround && velocity.y < 0)
velocity.y = -2f;
if ((isOnGround || canDoubleJump) && Input.GetKeyDown(KeyCode.Space))
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
canDoubleJump = !canDoubleJump;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.unscaledDeltaTime);
velocity.y += gravity * Time.unscaledDeltaTime;
controller.Move(velocity * Time.unscaledDeltaTime);
if (Input.GetKeyDown(KeyCode.Return))
stopTime();
}
}
the player controller script was made using brackeys’ tutorial.
i am not sure if making something happen during timeScale = 0 is even possible, pls tell me if it is possible im not sure.