Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by mohammed.romi · Mar 29, 2016 at 03:21 PM · unity 5gameobjecttextimage target

Dealing with objects and check each object name at runtime

Hi all please help me in this issue. I am developing an application using the unity and vuforia, my application write the image Target name when the object appear in a text field in canvas, i need to check when two objects appear the name of the two image targets and compare its if they equal a given value and then do a certain action. i connect each image target with different text field i will attach the code.

 using UnityEngine;
 using UnityEngine.UI;
 using System;
 namespace Vuforia
 {
     /// <summary>
     /// A custom handler that implements the ITrackableEventHandler interface.
     /// </summary>
     /// 
 
     public class DefaultTrackableEventHandler : MonoBehaviour,
                                                 ITrackableEventHandler
     {
 
         #region PRIVATE_MEMBER_VARIABLES
 
         public Text objectName,result;
 
         public string text ="";
         public string text2 ="";
         private TrackableBehaviour mTrackableBehaviour;
     
         #endregion // PRIVATE_MEMBER_VARIABLES
 
 
 
         #region UNTIY_MONOBEHAVIOUR_METHODS
     
         void Start()
         {
         
 
 
             mTrackableBehaviour = GetComponent<TrackableBehaviour>();
             if (mTrackableBehaviour)
             {
                 mTrackableBehaviour.RegisterTrackableEventHandler(this);
             }
 
         #endregion // UNTIY_MONOBEHAVIOUR_METHODS
 
 
 
         #region PUBLIC_METHODS
 
         /// <summary>
         /// Implementation of the ITrackableEventHandler function called when the
         /// tracking state changes.
         /// </summary>
         public void OnTrackableStateChanged(
                                         TrackableBehaviour.Status previousStatus,
                                         TrackableBehaviour.Status newStatus)
         {
             if (newStatus == TrackableBehaviour.Status.DETECTED ||
                 newStatus == TrackableBehaviour.Status.TRACKED ||
                 newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
             {
                 OnTrackingFound();
                 //OnGUI();
 
             }
             else
             {
                 OnTrackingLost();
             }
             check();
         }
 
         #endregion // PUBLIC_METHODS
 
 
 
         #region PRIVATE_METHODS
 
         private void OnTrackingFound()
         {
             Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
             Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
 
             objectName.text=gameObject.name;
             
                         if (gameObject.name == "Hydrogen")
                     text = "Hydrogen";
                 else
                     text2 = "Oxegen";
 
             // Enable rendering:
             foreach (Renderer component in rendererComponents)
             {
                 component.enabled = true;
 
 
                 }
            
 
             // Enable colliders:
             foreach (Collider component in colliderComponents)
             {
                 component.enabled = true;
                 
             }
             
 
 
 
 
             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
 
 
         }
 
         public void check(){
             
             if (text == "Hydrogen" && text2 == "Oxegen")
                 result.text = "Success";
             else
                 result.text = "fail";
         }
 
         private void OnTrackingLost()
         {
             Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
             Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
 
             objectName.text = "";
             result.text = "";
             // Disable rendering:
             foreach (Renderer component in rendererComponents)
             {
                 component.enabled = false;
             }
 
             // Disable colliders:
             foreach (Collider component in colliderComponents)
             {
                 component.enabled = false;
             }
 
             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
         }
 
         
         void Update(){
             //dont need to use Update.
         }
 
         /*void OnTriggerEnter(Collider other) {
             if(other.gameObject.tag == "object"){
                 //set text whatever you want.
             }
         }*/
 
         #endregion // PRIVATE_METHODS
     }
 }
 
 
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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how make object follow mouse cursor in 3d space 0 Answers

How to destroy only the collided instance of prefab and not the original one? 0 Answers

Cannot convert type `UnityEngine.GameObject[]' to `UnityEngine.GameObject' via a built-in conversion 1 Answer

Modals for 3D Objects/Environment 0 Answers

Changing the UI Text 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