Created
January 13, 2018 15:40
-
-
Save blue0513/cde46937a4cd49891b711550bc32ba67 to your computer and use it in GitHub Desktop.
Especially for iPad, it detects whether the device is moving or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment