一、顯示得分
1.修改 UI Scale Mode 為Scale With Screen Size
2.Game視窗與Canvas Scaler 的 Reference Resolution 改為一樣
3. Canvas/Text 改成 Score
4. 按下 Center 設定,按著Shift可以設定物件中心點座標,按Alt可以更改物件現在的位置。
5. Score 的Width & Height改大,讓文字顯示
6.增加component/Outline,可以設定光暈、顏色及透明度。
7. 新增空物件,命名為UiControl
8.新增腳本 UiControl.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class UiControl : MonoBehaviour {
public static int Score;
public Text ScoreBar;
// Use this for initialization
void Start () {
Score = 0;
}
// Update is called once per frame
void Update () {
ScoreBar.text = "" + Score;
}
}
9.將Score 拖到變數ScoreBar
10.增加分數
在碰撞cs中的Update()加入 UiControl.Score +=10;