【发布时间】:2016-05-23 14:03:46
【问题描述】:
是否可以从 c# 中的变量进行迭代?
我有变量public Transform dest1, dest2, dest3, dest4,... 和public StudentScript stu1, stu2, stu3, stu4, ...;,我想要的是如果与student1 发生冲突,那么agent 会从stu1 到dest1 和callscript,如果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") {
...
很抱歉问了这个类似初学者的问题
【问题讨论】:
-
@NicholasV.:通过在线阅读、参加课程、寻找导师...... StackOverflow 不是一个教程网站。
-
@EricLippert 我同意这一点。希望他不要觉得一个问题不受欢迎,因为他认为这是初学者。
标签: c# unityscript