加载中...

unity---克隆/贴图/平移/旋转

克隆

GameObject clone =Instantiate(gameObject,new Vector3(10,10,10),Quaternion.identity);

Destroy(clone,5);//5秒后自动销毁

image
image

添加图片

public Texture tex;//存储图片
Renderer ren;
ren =gameObject.GetComponent<Renderer>();
ren.material=null;
ren.material.mainTexture=tex;

image

平移

    if(Input.GetKey(KeyCode.RightArrow))this.gameObject.transform.Translate(new Vector3(0f,0f,Time.deltaTime*10));
    else if(Input.GetKey(KeyCode.LeftArrow))this.gameObject.transform.Translate(new Vector3(0f,0f,-Time.deltaTime*10));
    else if(Input.GetKey(KeyCode.UpArrow))this.gameObject.transform.Translate(new Vector3(Time.deltaTime*10,0f,0f));
    else if(Input.GetKey(KeyCode.DownArrow))this.gameObject.transform.Translate(new Vector3(-Time.deltaTime*10,0f,0f));

旋转

obj.transform.Rotate(0f,Time.deltaTime*50,0f);
posted @ 2022-03-16 17:33  lxp_blog  阅读(264)  评论(0编辑  收藏  举报