My goal is to make two methods one will loop and will get all the children objects that are only under Elevator.
The second one will loop and get all the children objects under Elevator and also if there are childs of childs to get them too like the OnTop Detector.
If i have now the method RotateChildren so to make another method like RotateChildren1 that will get all the childs of childs too.
In the Hierarchy i have under Elevator 3 children.
When i make a loop i’m getting only the first one the Platform. But i should get also the Platform1 and the Button.
I used a break point on the line:
if (child.name != "Platform")
And it stop only once on this line the name is Platform but it’s not continue to the Platform1 and to the Button.
using UnityEngine;
using System.Collections;
public class ObjectRotate : MonoBehaviour
{
public float multiplier = 10f;
private GameObject go;
void Start()
{
if (GameObject.Find("Elevator") != null)
{
go = GameObject.Find("Elevator");
}
RotateChildren(go.transform);
}
void OnMouseDrag()
{
transform.Rotate(Input.GetAxis("Mouse Y") * multiplier, -Input.GetAxis("Mouse X") * multiplier, 0, Space.World);
}
private void RotateChildren(Transform transform)
{
foreach (Transform child in transform)
{
if (child.name != "Platform")
child.parent = transform;
}
}
}