Log in or register to post comments

Unity3D - Enable/Disable JS Script Problem (AR) using CS

January 16, 2014 - 2:26am #1

Hi, i make an Augmented Reality Project use CS Script (DefaultTrackableEventHandler.cs) for enable and disable my JS Script Button (GUImenuTEST.js)

This my sample script :

using UnityEngine;
 
public class DefaultTrackableEventHandler : MonoBehaviour,
                                            ITrackableEventHandler
{
    private TrackableBehaviour mTrackableBehaviour;
 
    private GUImenuTEST jsScript;
 
    void Start()
    {
       jsScript = GetComponent<GUImenuTEST>();
 
       mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }
 
    }
 
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            OnTrackingFound();
 
         //THIS ERROR MESSAGE = error CS0120: An object reference is required to access non-static member `UnityEngine.Behaviour.enabled'
         GUImenuTEST.enabled = !GUImenuTEST.enabled; 
        }
        else
        {
            OnTrackingLost();
        }
    }
 
    private void OnTrackingFound()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }
        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    }
 
    private void OnTrackingLost()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }
        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    }
 
}

 

But, i have a error message like this " An object reference is required to access non-static member `UnityEngine.Behaviour.enabled' " on this code " GUImenuTEST.enabled = !GUImenuTEST.enabled; "

So, how to fix it ?
How to if i want to disable my Button Script (GUImenuTEST.js) if start running, and then will enable when TrackingFound, and disable again when TrackingLost ?
Please, help :)

Log in or register to post comments