Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- // Especially for iPad
- public class StandbyDirector : MonoBehaviour {
- private Vector3 acc = Vector3.zero;
- private Vector3 oldacc = Vector3.zero;
- private float timer = 0f;
- private bool isFinished = false;
- // custamizable
- private float threshold = 0.02f;
- private float standbyTime = 5f;
- // Update is called once per frame
- void Update () {
- goStandByIfNeeded();
- }
- // if device doesn't move, standby
- private void goStandByIfNeeded() {
- acc = Input.acceleration;
- float diff = Vector3.Distance(acc, oldacc);
- if(diff < threshold){
- timer += Time.deltaTime;
- if(timer > standbyTime && !isFinished){
- isFinished = true;
- standBy();
- }
- }else{
- timer = 0f;
- }
- oldacc = acc;
- }
- public void standBy() {
- Application.LoadLevel("YOUR Standby Scene Name");
- }
- }
Add Comment
Please, Sign In to add comment