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 HcKide · Dec 06, 2017 at 03:30 PM · unity 5scripting problembuttoncanvasvuforia

Script for activating next GameObject after first one has been found/tracked (Vuforia)

Hi guys/gals,

I'm making a small mobile application using Vuforia. It's supposed to be this sort of tour around my school, consisting out of multiple stations (6 so far). Upon detection of station 1, the button to station 1 appears for as long as station is being tracked on screen (Using the OnTrackingFound in DefaultTrackableEventHandler) and station 2 -> button 2 and so on... But since I want people to go from 1 -> 2 -> 3 etc. instead of random numbers I need all of them (except station 1) to be completely deactived at the start of the app, and then after Station 1 has been found, the next one is activated (including all parent objects and the buttons preferably). Im fairly new to scripting but any explanation/ help would be highly appreciated and I'll try my best to understand it. If any questions arise or something is unclear, feel free to ask and I'll try to elaborate more

alt text

Thanks in advance and with kind regards

capture.png (11.9 kB)
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

· Add your reply
  • Sort: 
avatar image
0

Answer by hallidev · Dec 08, 2017 at 03:07 PM

This script should do the trick for you:

 using UnityEngine;
 
 public class GameObjectActivator : MonoBehaviour
 {
     public GameObject[] GameObjects;
 
     private int _activeObjectIndex;
 
     public void Start ()
     {
         // Set first GameObject active by default
         setActiveGameObject(0);
     }
     
     public void Update ()
     {
         // This is your trigger for rotating through the active objects.
         // I picked "T" for "Toggle". It seems you'll be using OnTrackingFound. 
         // I'm not familiar with Vuforia, but as long as you increment _activeObjectIndex
         // and call setActiveGameObject(_activeObjectIndex), this should work for you.
         if (Input.GetKeyDown(KeyCode.T))
         {
             // Increment to next GameObject
             _activeObjectIndex++;
 
             // If we're on the last GameObject, wrap around back
             // to the first GameObject
             if (_activeObjectIndex > GameObjects.Length - 1)
             {
                 _activeObjectIndex = 0;
             }
 
             setActiveGameObject(_activeObjectIndex);
         }
     }
 
     private void setActiveGameObject(int index)
     {
         for (int i = 0; i < GameObjects.Length; i++)
         {
             GameObjects[i].SetActive(i == index);
         }
     }
 }
 

How to use:

  1. Create an Empty GameObject at your root. Name it GameObjectActivator or something similar.

  2. Attach this script

  3. Set the "GameObjects" property array size to the number of GameObjects you want to rotate through. I see 7 "Station" GameObjects in your screenshot.

  4. Drag each GameObject into a slot in the "GameObjects" property.

  5. Run the game and press "T" to toggle through them for testing.

You'll need to modify the script a bit to have it trigger when you want.

Hope this helps!

Comment
Add comment · 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

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

248 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use one button to play different audio for different Targets? 0 Answers

UI buttons don't work with Canvas Render Mode: Screen Space - Camera. 2 Answers

Highlight Button not working 1 Answer

UI Button not working? 0 Answers

AddListener fuction throwing a NullReferenceException error 1 Answer


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