hi , I have two objects in my app and they get enabled and disabled by touching a GUI button , the problem is when I enable and disable my objects I have to do it in update function , and these enabling and disabling in my javascript file interferes with the TrackableScript OnTrackingLost() and OnTrackingFound() functions , I wanted to define a bool variable in TrackableScript and assign it to true or false on OnTrackingLost() and OnTrackingFound() and then access this bool variable in my javascript file and solve this problem . is there any way to do this ?
thanks
- Sort Posts
- 4 replies
- Last post
accessing a variable from TrackableScript on another javascript file
Re: accessing a variable from TrackableScript on another javascr
Re: accessing a variable from TrackableScript on another javascr
You're absolutely right, using the Inspector was bad advice (I guess it doesn't work for components).
If your javascript is attached to another object than you should be able to get it using the GameObject.Find method:
MyJavascript myJS = (MyJavascript) FindObjectOfType(typeof(MyJavascript));
Note this is expensive, so you'll want to do it once when the script starts and cache the result.
- Kim
Re: accessing a variable from TrackableScript on another javascr
thanks kim , my scripts are not on the same object , I tried to do it with a public variable and then as you said drag my script on the inspector , but I can't do that , it doesn't allow me to drag the script on the public variable in the inspector . I placed my javascript file in the plugins forlder as you said . and in the editor even the auto complition tool had my javascript file as a variable type. I defined it like : "public mainScript js;" and it appears in the inspector but I can't drag and drop my mainScript.js on it in the inspector ;(
Re: accessing a variable from TrackableScript on another javascr
I think it might be easier to call javascript functions from the OnTrackingLost/OnTrackingFound methods. You could use that to set a variable in your javascript class, for instance.
You'll need to get a handle to the javascript object in C#. If the scripts are attached to the same object you can use the GetComponent() method, otherwise you could pass it in via a public member variable (and drag the javascript onto the field in the Inspector view).
The only trick here is to make sure your javascript file compiles first. You can do that by placing it in the Plugins folder, which is in an earlier compilation pass than our C# classes.
- Kim
thank you very much , worked !