是否有可能從c#中的變量進行迭代? 我有變數public Transform dest1, dest2, dest3, dest4,...
和public StudentScript stu1, stu2, stu3, stu4, ...;
,我想的是,如果發生碰撞student1接着劑去Dest1處,並從屋頂盒callscript,如果STUDENT2然後dest2和屋頂盒2 ...變量名迭代
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我在那裏。希望他不要因爲他認爲初學者而感到不受歡迎的問題。 –