无论摄像机拍摄到的图像怎么变换,GUI永远显示在屏幕上,不受变形、碰撞、光照的影响。
对话框、战斗值、能量等。
示例:用手机录像,摄像的参数不会随着拍摄场景变换。
GUI基础
GUI部分是每帧擦除重绘的,只应该在OnGUI中绘制GUI,按钮:GUILayout.Button(“Hello”);只读标签GUILayout.label()[注意脚本要实例化到GameObject上]
(引申)GUI有很对细节问题,比如GUI的绘制机制、如何响应鼠标点击、布局、如何获取设置控件。窗口等都和普通的窗口程序不一样()。其中还有NGUI、2DToolKit等

示例

在脚本中

    void OnGUI()
    {
        GUILayout.Button("hello");
    }

Material 是3D贴图;Texture是2D贴图,也就是GUI。

二、贴图材质Material画皮

  给GUI贴图:给脚本增加一个Texture类型的public字段,GUI.DrawTexture(new Rect(100,100,100,100),MyTexture);把Texture画到界面上指定区域。直接把图片从project拖到脚本的MyTexture属性上即可。
  做项目推荐定义public Texture的做法,这样可以方便美工修改贴图便于分工。
  建项目时候应该不同类别不同文件夹Images、Scripts、Audios、Vedios

 开发步骤

  1、在Assets中添加Images文件夹,增加需要的贴图图片

  2、在Assets中添加Materials文件夹,在文件夹中右键添加Material,命名为BoxMaterial,在Inspecttor中设置纹理等,纹理选用图片,Albedo前小圆点。

  3、静态资源绑定

    3.1、如果是静态资源,可以直接在Materials设置此项即可

    3.2、如果是动态加入

    1、先在脚本中增加属性,public Texture BoxMaterial;应该是简化的:public Texture BoxMaterial{get;set;}

    2、使用处增加:go.GetComponent<Renderer>().material = BoxMaterial;

    private GameObject goPlane;
    public Material BoxMaterial;

    // Use this for initialization
    void Start()
    {
        goPlane = GameObject.Find("Plane");
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                go.transform.position = new Vector3(i, j, -1);
                //if (j % 2 == 0)
                //{
                //    go.GetComponent<Renderer>().material.color = Color.red;
                //}
                go.AddComponent<Rigidbody>();
                go.GetComponent<Renderer>().material = BoxMaterial;
                go.AddComponent<AutoDestory>();
            }
        }

    }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-06-27
  • 2021-04-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案