预设体

作者: 胤醚貔貅 | 来源:发表于2017-04-11 16:20 被阅读20次

    usingUnityEngine;

    usingSystem.Collections;

    publicclassCreatGameObject:MonoBehaviour{

    public Transform fatherObject;

    public GameObject perfabs;

    private float time;

    //Usethisforinitialization

    voidStart(){

    //把预设体创建的游戏对象设置为某物体的子物体

    GameObjectplayer=Instantiate(perfabs,newVector3(-1.26f,2.5f,-1.5f),Quaternion.identity)asGameObject;

    player.transform.parent=fatherObject;//设置父物体

    player.name="laowang";

    //动态添加组件

    //CreatGameObjectobj=player.AddComponent();

    //

    //

    //CreatGameObjectobj=player.GetComponent();//获取组件

    //创建一个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){

    //

    ////通过预设体创建游戏对象

    //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;

    //}

    }

    }

    相关文章

      网友评论

          本文标题:预设体

          本文链接:https://www.haomeiwen.com/subject/mgluattx.html