Я пытаюсь получить только дочерние объекты GameObject первого уровня и добавить скрипт для каждого из дочерних объектов первого уровня.
Я получаю ошибку: addNavTagChildren.cs (14,21 ): ошибка CS0161: 'getFirstChildren (Transform)': не все пути кода возвращают значение
Вот мой код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class addNavTagChildren : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
List<GameObject> childrenList = new List<GameObject>();
//TEST
Transform[] getFirstChildren(Transform parent)
{
Transform[] children = parent.GetComponentsInChildren<Transform>();
Transform[] firstChildren = new Transform[parent.childCount];
int index = 0;
foreach (Transform child in children)
{
if (child.parent == parent)
{
firstChildren[index] = child;
index++;
childrenList.Add(child.gameObject);
}
}
}
for (int i = 0; i < childrenList.Count; i++)
{
NavMeshSourceTag nmst = childrenList[i].AddComponent<NavMeshSourceTag>();
}
}
}