unity中生成一个GUI格子(始终居中)

1.Script程序

using UnityEngine;
using System.Collections;

public class GUITest : MonoBehaviour
{   [SerializeField]
    float width;
    [SerializeField]
    float height;
    float xMin;
    float yMin;



    private void Start()
    {
        width = 100;
        height = 100;

    }

    void OnGUI()
    {
        xMin = 0.5f * Screen.width - width / 2;
        yMin = 0.5f * Screen.height - height / 2;

        print("height: "+ Screen.height);
        print("width: "+ Screen.width);

        Rect aa = new Rect(xMin, yMin, width, height);
        // Make a background box
        GUI.Box(aa, "GUI_TEST");
    }
}

2.OnGUI函数每隔一定时间被调用一次

void OnGUI()
{}

3.C#中变量定义时顺序不定,不能再声明时使用别的变量的值

猜你喜欢

转载自www.cnblogs.com/CK85/p/10313831.html
今日推荐