Search Unity

Timeout function with onTrackingBehavior extension

Discussion in 'Vuforia' started by VFurukawa, Feb 27, 2018.

  1. VFurukawa

    VFurukawa

    Joined:
    Jul 4, 2017
    Posts:
    6
    Hello. I'm trying to create a timeout screen in the main scene that drops you back into a static (non-vuforia) page after a certain amount of time. Right now I have it set to a certain time after the main scene is loaded. I need to be able to extend this time based on if the user is currently scanning targets. I tried pulling in the trackable behavior as an event that would start the clock from the last time that changed. However, I'm a scripting newb and am not doing so hot. I can't seem to get the OnTrackableStateChanged to run appropriately Any help is appreciated.
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.SceneManagement;
    6. using Vuforia;
    7.  
    8. public class sceneManagement : MonoBehaviour
    9. {
    10.     public float timeToIdle = 50.0f; //2 seconds
    11.     float currentTime = 0f;
    12.     float eventTime;
    13.     public bool idle = true;
    14.  
    15.  
    16.     void Start()
    17.     {
    18.         currentTime = Time.time + timeToIdle;
    19.         mTrackableBehaviour = GetComponent<TrackableBehaviour>();
    20.     }
    21.  
    22.     public void OnTrackableStateChanged(
    23.     TrackableBehaviour.Status previousStatus,
    24.     TrackableBehaviour.Status newStatus)
    25.     {
    26.         if (newStatus == TrackableBehaviour.Status.DETECTED ||
    27.         newStatus == TrackableBehaviour.Status.TRACKED ||
    28.         newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
    29.         {
    30.             currentTime = Time.time + timeToIdle;
    31.         }
    32.  
    33.      }
    34.  
    35.    
    36.     void Update()
    37.     {
    38.         if (!idle)
    39.         {
    40.             checkIdle();
    41.         }
    42.  
    43.  
    44.     }
    45.     void checkIdle()
    46.     {
    47.          if (Time.time > currentTime || Time.time - eventTime > currentTime)
    48.          {
    49.             idle = true;
    50.              Debug.Log("idling");
    51.              SceneManager.LoadScene("loading", LoadSceneMode.Single);
    52.      
    53.          }
    54.      
    55.     }
    56.  
    57.     public void loadMain()
    58.     {
    59.         SceneManager.LoadScene("main", LoadSceneMode.Single);
    60.  
    61.     }
    62.  
    63. }
    64.