Question by
GameDevH2O · Jul 28, 2018 at 11:34 PM ·
c#pauseaccelerometer
How to pause accelerometer movement
Hello so I figured out how to pause my game when it is disturbed
public static bool isPaused;
public GameObject pauseMenuUI;
void Start ()
{
isPaused = false;
Time.timeScale = 1;
}
public void GamePause()
{
isPaused = !isPaused;
if (isPaused)
Time.timeScale = 0;
pauseMenuUI.SetActive(true);
if (!isPaused)
Time.timeScale = 1;
}
void OnApplicationPause()
{
pauseMenuUI.SetActive(true);
isPaused = true;
Time.timeScale = 0;
}
public void Resume ()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1;
isPause = false;
}
It pauses everything but the acceleration of the player
float accelStartY;
void Start()
{
accelStartY = Input.acceleration.y;
}
void Update()
{
transform.Translate(Input.acceleration.x, Input.acceleration.y - accelStartY, 0);
//PauseScript is script above
if (PauseScript.isPaused)
{
Time.timeScale = 0;
}
I need help pausing my player
Comment
Answer by UnityCoach · Jul 28, 2018 at 11:56 PM
If you multiply it by Time.deltaTime, it'll scale as well..
transform.Translate(Input.acceleration.x * Time.deltaTime, Input.acceleration.y * Time.deltaTime, 0);
It worked but it slowed the acceleration speed down when being played.
Yes, of course, you usually want to multiply it by a speed value then.
transform.Translate(Input.acceleration.x * speed * Time.deltaTime, Input.acceleration.y * speed * Time.deltaTime, 0);
Note that it's also usually good practice when you want a frame rate independent motion, unless you use raw input, like when using Gyroscope input for rotation.