坦克小戰之GUI的界面

這裏寫圖片描述
界面就是一個分數一個生命值,

這是生命

public GameObject tank;//這個是自己哦
    private TankController tc;
    void Start () {
        tc  = tank.GetComponent<TankController>();
    }
    void Update () {}
    void OnGUI()
    {
        GUI.skin.label.fontSize = 30;
        GUI.color = Color.red;
        string content = "生命 : " + tc.health.ToString ();
        GUI.Label (new Rect(0,Screen.height/8,Screen.width/5,Screen.height/8),content);
    }

這是分數:

public int score= 0;

    void Start () {}
    void Update () {}
    void OnGUI()
    {
        GUI.skin.label.fontSize = 30;
        GUI.color = Color.blue;
        string content = "分數 : " + score.ToString ();
        GUI.Label (new Rect(0,0,Screen.width/5,Screen.height/8),content);
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章