【Unity】脚本:UI界面实现基本按键操作物体移动

点击UI界面摁按钮,实现对应移动等功能

    private void Update()
    {
        time = Time.time;
        if(time_go == 1)
        {
            this.transform.position += Vector3.forward * Time.deltaTime;
            
        }
    }
    private void OnGUI()
    {
        if (GUILayout.Button("Tag"))
        {
            //print("ok");
            print(this.tag);
        }
        if (GUILayout.Button("位置重置"))
        {
            this.transform.position = new Vector3(0, 0, (float)-6.57);
        }
        if (GUILayout.Button("Z方向移动10m"))
        {
            this.transform.position = new Vector3(0, 0, 10);
        }
        if(GUILayout.Button("持续移动"))
        {
            time_go = 1;
        }
        if (GUILayout.Button("停止移动"))
        {
            time_go = 0;
        }
        if (GUILayout.Button("变成红色"))
        {
            this.GetComponent<MeshRenderer>().material.color = Color.red;
        }
    }

以上

posted @ 2022-04-08 11:07  HanaKoo  阅读(134)  评论(0编辑  收藏  举报
@format