gpt4 book ai didi

c# - 带变量名的迭代

转载 作者:太空宇宙 更新时间:2023-11-03 21:11:24 26 4
gpt4 key购买 nike

<分区>

是否可以从 C# 中的变量进行迭代?我有变量 public Transform dest1, dest2, dest3, dest4,...public StudentScript stu1, stu2, stu3, stu4, ...; 我想要的是如果与 student1 发生碰撞,则 agent 转到 dest1 并从 stu1 调用脚本,如果与 student2 发生碰撞,则 dest2 和 stu2...

if (Physics.Raycast (ray, out hit)) {
if (hit.collider.name == "_student1") {
Debug.Log (hit.transform.name);
agent.SetDestination (dest1.position);
if (Mathf.Abs (tagent.position.x - dest1.position.x) <= closeEnough && Mathf.Abs (tagent.position.z - dest1.position.z) <= closeEnough) {
stu1.ResetStudentBehaviour();
}
}else if (hit.collider.name == "_student2") {
agent.SetDestination (dest2.position);
if (Mathf.Abs (tagent.position.x - dest2.position.x) <= closeEnough && Mathf.Abs (tagent.position.z - dest2.position.z) <= closeEnough) {
stu2.ResetStudentBehaviour();
}
}else if (hit.collider.tag == "_student3") {
...

很抱歉问了这个像初学者一样的问题

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com