Unity 6.3
0 онлайн 30 гостей 3 в системе
Вход

Transform.GetChild

Declaration

public Transform GetChild(int index);

Параметры

Параметр Описание
индекс Индекс возвращаемого дочернего преобразования. Должно быть меньше Transform.childCount.

Возвращаемое значение

Transform Transform дочерние по индексу.

Описание

Возвращает дочернее преобразование по индексу.

Если у Transform нет дочерних объектов или значение аргумента index больше их количества, возникает ошибка. В этом случае выводится сообщение "Transform child out of bounds". Количество дочерних объектов можно получить с помощью childCount.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform meeple; public GameObject grandChild;

public void Example() { //Assigns the transform of the first child of the Game Object this script is attached to. meeple = this.gameObject.transform.GetChild(0);

//Assigns the first child of the first child of the Game Object this script is attached to. grandChild = this.gameObject.transform.GetChild(0).GetChild(0).gameObject; } }