Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Nov 10, 2015 at 07:27 AM by ar4ta for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ar4ta · Jan 16, 2014 at 09:50 AM · buttonvuforiahide

Enable/Disable JS Script Problem (AR) using CS

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 :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0

Answer by mohanrao164 · Jan 16, 2014 at 09:57 AM

replace this code

jsScript = (GUImenuTEST)findObjectOfType(typeof(GUImenuTEST));

and place the GUImenuTEST script in plugins folder.then only u can call javascript in C#

Comment
Add comment · Show 13 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ar4ta · Jan 16, 2014 at 10:10 AM 0
Share

Thanks for answer, but i still have an error message :(

"Assets/Qualcomm Augmented Reality/Scripts/DefaultTrackableEventHandler.cs(32,49): error CS0103: The name `findObjectOfType' does not exist in the current context"

avatar image mohanrao164 · Jan 16, 2014 at 10:24 AM 0
Share

add this header using System.Collections; and did u place script in plugins folder and it is FindObjectOfType not findObjectOfType the starting letter should be capital

avatar image mohanrao164 · Jan 16, 2014 at 10:47 AM 0
Share

ok can i see what are you calling in start function and also try your default code once i.e jsScript = GetComponent(); and check both conditions once.

avatar image ar4ta · Jan 16, 2014 at 10:48 AM 0
Share

Sorry its work, but how to disable/enable my GUImenuTEST.js ? I mean, 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 ?

avatar image ar4ta · Jan 16, 2014 at 10:52 AM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class DefaultTrackableEventHandler : $$anonymous$$onoBehaviour,
                                             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.TRAC$$anonymous$$ED ||
             newStatus == TrackableBehaviour.Status.EXTENDED_TRAC$$anonymous$$ED)
         {
             OnTrackingFound();
             jsScript = (GUImenuTEST)FindObjectOfType(typeof(GUImenuTEST)); 
         }
         else
         {
             OnTrackingLost();
         }
     }
 
     private void OnTrackingFound()
     {
         Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
         Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
     
         foreach (Renderer component in rendererComponents)
         {
             component.enabled = true;
         }
 
         foreach (Collider component in colliderComponents)
         {
             component.enabled = true;
         }
 
         Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
     }
 
     private void OnTrackingLost()
     {
         Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
         Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
         
         foreach (Renderer component in rendererComponents)
         {
             component.enabled = false;
         }
 
         foreach (Collider component in colliderComponents)
         {
             component.enabled = false;
         }
         
         Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
     }
 
 }
 
Show more comments

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make a function not appear on UnityEvents / Button OnClick lists? 0 Answers

How to toggle object visibility with keyboard button? 1 Answer

how I can hide a canvas in Unity and shows it after some days using C# Script ? 1 Answer

Cloud recognition in Vuforia 0 Answers

Hide virtual object behind real object detect by Vuforia 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges