usingUnityEngine;
usingSystem.Collections;
publicclassCreatGameObject:MonoBehaviour{
public Transform fatherObject;
public GameObject perfabs;
private float time;
//Usethisforinitialization
voidStart(){
//把預設(shè)體創(chuàng)建的游戲?qū)ο笤O(shè)置為某物體的子物體
GameObjectplayer=Instantiate(perfabs,newVector3(-1.26f,2.5f,-1.5f),Quaternion.identity)asGameObject;
player.transform.parent=fatherObject;//設(shè)置父物體
player.name="laowang";
//動態(tài)添加組件
//CreatGameObjectobj=player.AddComponent();
//
//
//CreatGameObjectobj=player.GetComponent();//獲取組件
//創(chuàng)建一個ball作為cube的子物體仓洼,并且在5秒之后銷毀
GameObjectball=Instantiate(ballPrefabs,newVector3(-1f,1.5f,-1f),Quaternion.identity)asGameObject;
//ball.transform.SetParent(transform);
ball.transform.parent=fatherObject;
GameObject.Destroy(ball,5.0f);
}
//Updateiscalledonceperframe
voidUpdate(){
//time+=Time.deltaTime;
//if(time>=4.0f){
//
////通過預設(shè)體創(chuàng)建游戲?qū)ο?/p>
//GameObjectplayer=Instantiate(perfabs);
//player.transform.position=newVector3(2f,0.5f,-3.4f);
//player.transform.rotation=Quaternion.identity;
//
//
////????????????GameObject?player_2?=?Instantiate?(perfabs,?new?Vector3?(3,?0.5f,?3),?Quaternion.identity)?as?GameObject?;
//
//
//time=0.0f;
//}
}
}