- Home /
Moving from one object to another object either forward or backward in the SAME SCENE
Hi, I have all my objects placed in only ONE SCENE say object A, B, C, D and E. 1. As soon as my application is started i am trying to show only one object at the beginning(Say object A) and all the other objects are hidden/ 2. then after air tap on object A 3. Object B and Object C should be seen 4. Now when I airtap on B,I am trying to show object D 5. Now when I airtap on C,I am trying to show object E 6. On giving a voice command "Back" on D , I am trying to show object B 7. On giving a voice command "Home" on object D or object E , I am trying to show object A
So,are there any methods available to show the above flow. If possible provide the links if available. Please help Thanks :)
Answer by Mister-Mortal · Nov 28, 2016 at 02:17 PM
You could use this class, you just need to write methods to call OnTouch() and OnBack()
public class ObjectTree : MonoBehaviour
{
public GameObject[] ObjectsOnTouch;
public GameObject[] ObjectsOnBack;
public GameObject[] ObjectsToDisable;
public void DisableObjects()
{
foreach (var objectToDisable in ObjectsToDisable)
{
objectToDisable.SetActive(false);
}
}
public void OnTouch()
{
DisableObjects();
foreach (var objectToEnable in ObjectsOnTouch)
{
objectToEnable.SetActive(true);
}
}
public void OnBack()
{
DisableObjects();
foreach (var objectToEnable in ObjectsOnBack)
{
objectToEnable.SetActive(true);
}
}
}
Add this script to the object you will be clicking on and in the inspector drag game objects that you will enable on touch in ObjectsOnTouch field, objects that appears when going back to ObjectsOnBack field and objects that you will disable to ObjectsToDisable field.
Your answer
![](https://koobas.hobune.stream/wayback/20220612101603im_/https://answers.unity.com/themes/thub/images/avi.jpg)