【发布时间】:2021-03-29 15:23:26
【问题描述】:
如何通过 if(); 运算符上的名称使用数组中的特定游戏对象?
我现在那个,不能隐式转换类型string[]' to string',但必须是另一种方式?
List <GameObject> cubes = new List<GameObject> ();
private void OnCollisionEnter(Collision coll)
{
if (coll.gameObject.tag == "ground")
{
coll.gameObject.GetComponent<Renderer>().material.SetColor("_Color", Color.red);
cubes.Add (coll.gameObject);
string[] ar1 = {"a1","a2" ,"a3","a4"};
if (cubes.Count > 4) {
foreach(GameObject go in cubes){
if (go.name == ar1) {
Debug.Log ("PASSED");
}
}
【问题讨论】:
-
这个有点不清楚。
-
当数组中的特定游戏对象为 OnCollisionEnter 时,必须工作。
-
我想在'if()'操作符的数组中获取游戏对象名称