英文:
How can I acsess transform of child from a different gameobject
问题
我正在制作一个NPC漫游系统,并已经烘焙了导航网格,但我想知道如何获取子物体的变换(我有一个空的游戏对象,其中包含所有的目的地)。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Apple;
public class PersonBehaviour : MonoBehaviour
{
public GameObject destinationParent; // 空的游戏对象
private int chosenDestination;
private GameObject destination;
private int destinationCount;
private Transform destinatonTransform;
void Start()
{
destinationParent = GameObject.Find("Destinations");
destinationCount = destinationParent.transform.childCount;
chosenDestination = Random.Range(0, destinationCount + 1);
// destinatonTransform = 如何获取子物体的变换?
}
}
请注意,你需要补充如何获取子物体的变换的代码。
英文:
Im making an NPC wandering system and have baked the navmesh and all but i want to know how i can get the childs transform (i have aan epty gameobject eith all the destinations)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Apple;
public class PersonBehaviour : MonoBehaviour
{
public GameObject destinationParent; // the empty game object
private int chosenDestination;
private GameObject destination;
private int destinationCount;
private Transform destinatonTransform;
void Start()
{
destinationParent = GameObject.Find("Destinations");
destinationCount = destinationParent.transform.childCount;
chosenDestination = Random.Range(0, destinationCount + 1);
//destinatonTransform = ???????
}
}
答案1
得分: -1
如果 chosenDestination 是你正在搜索的索引,这可能是一个解决方案。
destinationParent.transform.GetChild(chosenDestination).transform;
英文:
If the chosenDestination is the index that you are searching for this could be a solution.
destinationParent.transform.GetChild(chosenDestination).transform;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论