一、GameObject类的使用
//Debug.Log(gameObject.name);//查找物体的名字
// GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);//创建一个Cube
// //给Cube指定一个父对象
//transform.parent = cube.transform;
// //把物体从父节点中移除
// GameObject sh = GameObject.Find("Sphere");
// sh.transform.SetParent(null);
// Debug.Log("孩子节点数" + transform.childCount);
//for (int i = 0; i < transform .childCount ; i++)
//{
// Debug.Log(i + " " + transform.GetChild(i).name);
//}
///查找游戏对象的位置,根据名字查找
//GameObject c = GameObject.Find("Cube");
//Debug.Log(c.transform.position);
//GameObject A = GameObject.Find("Sphere");
//Debug.Log(A.transform.position);
///找找一组的游戏对象
//GameObject b = GameObject.FindWithTag("zz");
//GameObject bj = GameObject.FindGameObjectWithTag("zz");
//GameObject[] obj = GameObject.FindGameObjectsWithTag("zz");
//for (int i = 0; i < obj.Length ; i++)
//{
// Debug.Log(obj[i].transform.position);
//}
///设置游戏对象的Tag值
///
//GameObject cylinder = GameObject.Find("Cylinder");
//cylinder.tag = "zz";
///将游戏对象失活(隐藏)
//cylinder.SetActive(false);
//cylinder.Destroy(cylinder,3);
///克隆游戏对象
GameObject spheres = GameObject.Instantiate(Spheresprefabs);
spheres.name = "Spheres";
GameObject spheres1 = GameObject.Instantiate(Spheresprefabs, new Vector3(2, 2, 2), Quaternion.identity) as GameObject;
spheres1.name = "zz";
GameObject spheres2 = GameObject.Instantiate<GameObject>(Spheresprefabs);
spheres2.transform.position = new Vector3(3, 3, 3);
spheres2.name = "zz";
二、Transform类的使用
//GameObject obj = GameObject.Find("Sphere ()5");
//obj.transform.SetAsFirstSibling();
///把某个物体向前移
//Transform trans = transform.GetChild(5);
//int index = trans.GetSiblingIndex();
//trans.SetSiblingIndex(3);
三、GameObject类和Transform类查找的区别
///查找子物体,能找到是活的物体
Transform child1 = transform.Find("Sphere");
Debug.Log(child1.name);
//查找整个面板,不能到失活的对象
GameObject child = GameObject.Find("Sphere");
Debug.Log(child.name);