How do I pause the accelerometer?
what code do i need to pause a game that use the accelerometer to move the player? i've tried the code below, but didn't work
#pragma strict
var pause : boolean = false;
function OnGUI()
{
if (GUI.Button (Rect((Screen.width/2)-75,70,95,45), "PAUSE"))
{
if (pause == false)
{
pause = true ;
Time.timeScale = 1 ;
return;
}
if (pause == true)
{
pause = false;
Time.timeScale = 0 ;
return;
}
}
}
Answer by faraioswald · Apr 08, 2016 at 06:58 PM
@Caiogb As for me i did this and it worked i have a script which controls the accelerometer only called Accelorometer. My way is to disable this script(Accelorometer) when i press the pause button, then when i press the continue/resume button i enable the script. To do this create a new c# script with these methods
public Accelerometer Acc;
void Start()
{
Acc = GetComponent<Accelerometer> ();
}
public void DisableAcc()
{
Acc.enabled = false;
}
public void EnableAcc()
{
Acc.enabled = true;
}
// Now go to your pause button where there is On Click() click the + and drag the gameObject with the Accelerometer and drop it on the empty slot. Click the No Function button and put the DisableAcc() method. Then go to your continue/resume button click the + and drag the gameObject with the Accelerometer and drop it on the empty slot. Click the No Function button and put the EnableAcc() method. That should do it. It worked for me.
Your answer
Follow this Question
Related Questions
Accelerometer Input for cube movement (android) 0 Answers
Pause Button Issue android 0 Answers
How to get Android classes - like SensorMenager - in unity script 0 Answers
Android Roll-a-ball jump? 0 Answers
Gravity on Android 1 Answer