Log in or register to post comments

Timeout function with onTrackingBehavior extension

March 1, 2018 - 7:00am #1

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.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Vuforia;

public class sceneManagement : MonoBehaviour
{
    public float timeToIdle = 50.0f; //2 seconds
    float currentTime = 0f;
    float eventTime;
    public bool idle = true;


    void Start()
    {
        currentTime = Time.time + timeToIdle;
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
    }

    public void OnTrackableStateChanged(
    TrackableBehaviour.Status previousStatus,
    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
        newStatus == TrackableBehaviour.Status.TRACKED ||
        newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            currentTime = Time.time + timeToIdle;
        }

     }

 
    void Update()
    {
        if (!idle)
        {
            checkIdle();
        }


    }
    void checkIdle()
    {
         if (Time.time > currentTime || Time.time - eventTime > currentTime)
         {
            idle = true;
             Debug.Log("idling");
             SceneManager.LoadScene("loading", LoadSceneMode.Single);
   
         }
   
    }

    public void loadMain()
    {
        SceneManager.LoadScene("main", LoadSceneMode.Single);

    }

}
Log in or register to post comments