Sleep phone when not in motion
Hi,
I am building an app which runs on a smartphone attached to a rotating object. When the phone rotates, the gyro detects this and changes the image. However, to avoid overheating on the device I would like the app to "sleep" after 60 seconds of no motion.
I am using input.gyro to move the camera using this script I got from the forums, modified a little so it only rotates on y.
using UnityEngine;
using System.Collections;
// Activate head tracking using the gyroscope
public class GyroCamera : MonoBehaviour {
public GameObject player; // First Person Controller parent node
public GameObject head; // First Person Controller camera
// The initials orientation
private float initialOrientationX;
private float initialOrientationY;
private float initialOrientationZ;
// Use this for initialization
void Start () {
// Activate the gyroscope
Input.gyro.enabled = true;
// Save the firsts values
initialOrientationX = Input.gyro.rotationRateUnbiased.x;
initialOrientationY = Input.gyro.rotationRateUnbiased.y;
initialOrientationZ = -Input.gyro.rotationRateUnbiased.z;
}
// Update is called once per frame
void Update () {
// Rotate the player and head using the gyroscope rotation rate
player.transform.Rotate (0, initialOrientationY -Input.gyro.rotationRateUnbiased.y, 0);
// head.transform.Rotate (initialOrientationX -Input.gyro.rotationRateUnbiased.x, 0, initialOrientationZ + Input.gyro.rotationRateUnbiased.z);
}
}
I am also using the following script attached to a empty gameobject to sleep:
using UnityEngine;
using System.Collections;
public class sleeptimeout : MonoBehaviour {
void Update() {
Screen.sleepTimeout = 60;
}
}
however, the app never sleeps. Can anyone spot the problem?
I'm not sure, but resetting the timeout every Update could be resetting the start time. try doing it in Start.
Your answer
Follow this Question
Related Questions
How do I use both touch and gyro to transform rotate the camera? 3 Answers
Rotate a Quaternion 0 Answers
Get single axis from gyroscopic input (iOS) 0 Answers
Ignore gyroscope yaw 0 Answers