Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. // Especially for iPad
  6. public class StandbyDirector : MonoBehaviour {
  7. private Vector3 acc = Vector3.zero;
  8. private Vector3 oldacc = Vector3.zero;
  9. private float timer = 0f;
  10. private bool isFinished = false;
  11.  
  12. // custamizable
  13. private float threshold = 0.02f;
  14. private float standbyTime = 5f;
  15.  
  16. // Update is called once per frame
  17. void Update () {
  18. goStandByIfNeeded();
  19. }
  20.  
  21. // if device doesn't move, standby
  22. private void goStandByIfNeeded() {
  23. acc = Input.acceleration;
  24. float diff = Vector3.Distance(acc, oldacc);
  25.  
  26. if(diff < threshold){
  27. timer += Time.deltaTime;
  28. if(timer > standbyTime && !isFinished){
  29. isFinished = true;
  30. standBy();
  31. }
  32. }else{
  33. timer = 0f;
  34. }
  35.  
  36. oldacc = acc;
  37. }
  38.  
  39. public void standBy() {
  40. Application.LoadLevel("YOUR Standby Scene Name");
  41. }
  42. }
Add Comment
Please, Sign In to add comment