title: Activate and Desactivate GameObjects by toggles - Augmented Reality
body: <p>I'm making an application with Augmented Reality using ArToolkit.</p>
  
  <p>It's very simple.</p>
  
  <p>I show some elements accord the toggle stage. Example, I've 3 elements</p>
  
  <p><a href="https://i.stack.imgur.com/yrM9l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yrM9l.png" alt="3 Elements"></a></p>
  
  <p>When I run, one element is displayed. If I click in first <code>toggle</code> this element hide and the next element show. When I click in second <code>toggle</code> the previous element hide and the next is show.</p>
  
  <p>In another words, when I run only the first element (Cube) is displayed. When I click in first  toggle, each element (cube, esphere, cilinder) is show:</p>
  
  <p><strong>Step 1:</strong>
  <a href="https://i.stack.imgur.com/RmT4S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RmT4S.png" alt="Step1"></a> </p>
  
  <p><strong>Step 2:</strong>
  <a href="https://i.stack.imgur.com/ioCnK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ioCnK.jpg" alt="step2"></a></p>
  
  <p><strong>Step 3:</strong>
  <a href="https://i.stack.imgur.com/jVePx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jVePx.jpg" alt="step3"></a> </p>
  
  <p>This is my hierarchy:</p>
  
  <p><a href="https://i.stack.imgur.com/uQIuO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uQIuO.png" alt="hierarchy"></a></p>
  
  <p>Inside <code>ArControlador</code> are the markers. Inside <code>Canvas</code> are the toggles.</p>
  
  <p>But, actually I build this project in rude way, getting each element with <code>GameObject.Find</code>. I want get the GameObjects in in elegance way, clean code and it can be scaleable.</p>
  
  <p>I want get the GameObjects in an automated way, so if I have 3, 5, 10 or 20 elements the code will run perfectly.</p>
  
  <p>I think in some possibilities like <code>Array</code> of <code>GameObjects</code>, <code>List</code> of <code>GameObjects</code>, create a <code>GameObject</code> father and get all childs like <code>FindGameObjectsWithTag</code> but I don't have successfull.</p>
  
  <p>This is my code, it already works but in rude way, geting <code>GameObject</code> per <code>GameObject</code> and enable/disable the GameObjects with <code>aux</code> variable, see:</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using UnityEngine.UI;
  using UnityEngine.EventSystems;
  using System.Linq;
  using System.Collections.Generic;
  using System;
  using UnityEngine.SceneManagement;
  
  public class AlternaEntreOsPassos : MonoBehaviour
  {
      private UnityEngine.UI.Toggle[] toggles;
      public int aux = 0;
  
      public GameObject marker1, marker2, marker3;
  
          void Awake()
      {
          //Find manually the objects
          marker1 = GameObject.Find("Marcador1");
          marker2 = GameObject.Find("Marcador2");
          marker3 = GameObject.Find("Marcador3");
      }
  
  
      void Start()
      {
          toggles = GetComponentsInChildren&lt;UnityEngine.UI.Toggle&gt;();
  
  
          if (toggles.Length &gt; 0)
          {
  
              //2nd and 3rd false for not be displayed yet...
              marker2.SetActive(false);
              marker3.SetActive(false);
  
              for (int i = 0; i &lt; toggles.Length; i++)
              {
  
                  int closureIndex = i;               
                  toggles[closureIndex].interactable = false;
                  toggles[closureIndex].onValueChanged.AddListener((isOn) =&gt;
                  {
                      if (isOn == true)
                      {
                          aux++;
  
                          //Disabling the toggle that was clicked
                          toggles[closureIndex].interactable = false;
  
                          if (closureIndex &lt; toggles.Length - 1)
                          {
                              //Activatin the next toggle
                              toggles[closureIndex + 1].interactable = true;                           
                          }
  
                          if (aux == 1)
                          {
                              //Desactivating the actual element and activating the next element
                              marker1.SetActive(false);
                              marker2.SetActive(true);
                          }
  
                          if (aux == 2)
                          {
                              //Desactivating the actual element and activating the next element
                              marker2.SetActive(false);
                              marker3.SetActive(true);
                          }
  
                          if (aux == 3)
                          {
                              marker3.SetActive(false);
                          }
  
                      }
                  }
              );
  
              }
  
              toggles[0].interactable = true;
          }     
      }
  }
  </code></pre>
  
  <p>So, how I can get the <code>GameObjects</code> in intelligent way like the examples above (<code>array</code>, <code>list</code>, <code>tag</code>) or something else.</p>