unity3d c#数组简单问题 15
publicclassshanchu:MonoBehaviour{publicGameObjectHh1;publicGameObjectHh2;publicGameOb...
public class shanchu : MonoBehaviour { public GameObject Hh1; public GameObject Hh2; public GameObject Hh3; public GameObject Hh4; int i=1; void OnClick () { string[] Hh = {"Hh0","Hh1","Hh2","Hh3","Hh4"}; if(i<4){ GameObject gg=Instantiate(Hh[i], GameObject.Find("Cube/quan/d1_"+i.ToString()).transform .position, GameObject.Find("Cube/quan/d1_"+i.ToString()).transform.rotation)as GameObject; gg.transform.parent=(GameObject.Find("Cube/quan")).transform; Destroy(GameObject.Find("Cube/quan/d1_"+i.ToString())); i++; } print (Hh[i]); //print (i); } } 不好用Hh[i],不知道怎么表达。不知道那错了请高手指点
public class shanchu : MonoBehaviour {
public GameObject Hh1;
public GameObject Hh2;
public GameObject Hh3;
public GameObject Hh4;
int i=1;
void OnClick ()
{
string[] Hh = {"Hh0","Hh1","Hh2","Hh3","Hh4"};
if(i<4){
GameObject gg=Instantiate(Object.Hh[i], GameObject.Find("Cube/quan/d1_"+i.ToString()).transform .position, GameObject.Find("Cube/quan/d1_"+i.ToString()).transform.rotation)as GameObject;
i++;
}
print (Hh[i]);
//print (i);
}
} 展开
public class shanchu : MonoBehaviour {
public GameObject Hh1;
public GameObject Hh2;
public GameObject Hh3;
public GameObject Hh4;
int i=1;
void OnClick ()
{
string[] Hh = {"Hh0","Hh1","Hh2","Hh3","Hh4"};
if(i<4){
GameObject gg=Instantiate(Object.Hh[i], GameObject.Find("Cube/quan/d1_"+i.ToString()).transform .position, GameObject.Find("Cube/quan/d1_"+i.ToString()).transform.rotation)as GameObject;
i++;
}
print (Hh[i]);
//print (i);
}
} 展开
2个回答
展开全部
最上边的定义变成public GameObject HhObj[] = new GameObject[4];
在属性面板(inspector)中拖放相应的prefab。
下边的实例化
GameObject gg=Instantiate(HhObj[i], GameObject.Find("Cube/quan/d1_"+i.ToString()).transform .position, GameObject.Find("Cube/quan/d1_"+i.ToString()).transform.rotation)as GameObject;
在属性面板(inspector)中拖放相应的prefab。
下边的实例化
GameObject gg=Instantiate(HhObj[i], GameObject.Find("Cube/quan/d1_"+i.ToString()).transform .position, GameObject.Find("Cube/quan/d1_"+i.ToString()).transform.rotation)as GameObject;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
GameObject gg=Instantiate(Object.Hh[i], GameObject.Find("Cube/quan/d1_"+i.ToString()).transform .position, GameObject.Find("Cube/quan/d1_"+i.ToString()).transform.rotation)as GameObject;
这一句写的有点复杂,我表示看不下去……
这一句写的有点复杂,我表示看不下去……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询