我正在試圖製作一個快速的GUI進度條,顯示您在關卡中的進度。Unity 5 C#GUI - 根據目標完成距離製作進度條。
這是我現在的代碼,我必須做些什麼才能使它起作用?
using UnityEngine;
using System.Collections;
public class Distance : MonoBehaviour {
private float finalGoal_dist = 0.0f;
public Transform Player;
public Transform finalGoal;
public Vector2 pos = new Vector2(20, 40);
public Vector2 size = new Vector2(120, 120);
public Texture2D emptyTex;
public Texture2D fullTex;
void OnGUI(){
GUI.Box(new Rect(0,0, size.x, size.y), emptyTex);
GUI.Box(new Rect(0,0, size.x*t, size.y), fullTex);
}
// Update is called once per frame
void Update() {
finalGoal_dist = Vector3.Distance(Player.position, finalGoal.position);
print("Distance to Goal:" + finalGoal_dist);
}
}
什麼不工作? –
GUI沒有連接到finalGoal_dist,我不確定如何做到這一點。 – user3708761