【发布时间】:2020-03-04 15:03:56
【问题描述】:
所以我试图将数组中对象的位置与我拥有的 int 变量进行比较
我有一个名为 stagePos 的变量,我想用它来找到一个对象,它在数组中的位置具有相同的值
如果 stagePos 为 1,那么我想在数组中找到一个位置为 [1] 的对象,并对其进行处理以及对该数组中的其他对象进行处理,因为它们没有与stagePos相同的值
if(stage[i] != stage[stagePos]){
Vector3 pos = stage[i].transform.position;
pos += new Vector3(0f, -4f * Time.deltaTime , 0f);
stage[i].transform.position = pos;
stageScript.Invinsible(true);
}
else if(stage[i] == stage[stagePos]){
Vector3 pos = stage[i].transform.position;
pos += new Vector3(0f, 4f * Time.deltaTime, 0f);
stage[i].transform.position = pos;
stageScript.Invinsible(false);
}
【问题讨论】:
-
stage持有什么类型的对象? -
if (i ==stagepos) ....
-
stage 拥有一个公共 GameObject[] 舞台;
-
如果 stagePos 是 int,那么您遇到了什么问题?
-
如果stagePos是一个Vector3,通过
stage.IndexOf(stagePos)找到它的索引