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函數每隔必定時間被調用一次3d

void OnGUI()
{}

3.C#中變量定義時順序不定,不能再聲明時使用別的變量的值blog

相關文章
相關標籤/搜索