- Home /
converting from GUI text to GUI Labels
I am attempting to take my project from its rough beginnings to be something that us a lot more cleaned up. Currently I am working on getting the GUI cleaned up but I am having some trouble using GUI Labels. I have 3 elements for my ingame HUD, a simple health display (that will become image based eventually), a timer and a score, the code for each is as follows.
//healthGUI.js
var healthLeft : GUIText;
var playerStat;
var healthStart : int;
function Start(){
playerStat = GameObject.FindWithTag("Player").GetComponent(CharacterCont);
}
function Update () {
healthLeft.text = String.Format("{0}/3",playerStat.health);
}
//timerGUI.js
var min : int;
var sec : int;
var fraction : int;
var timecount : float;
var starttime : float;
var timeCounter : GUIText
function Start (){
starttime = Time.time;
}
function Update () {
timecount = Time.time - starttime;
min = (timecount/60f);
sec = (timecount % 60f);
fraction = ((timecount * 10) %10);
timeCounter.text = String.Format("{0:00}:{1:00}:{2:00}",min,sec,fraction);
}
//highscoreGUI.js
var currentScore : GUIText;
var enemyTracker;
function Start(){
enemyTracker = GameObject.FindWithTag("GameController").GetComponent(enemystate);
}
function Update () {
currentScore.text = String.Format("{0}",enemyTracker.killed);
}
Im just wondering if there is a simple solution to this or somewhere I can read up on how to make these sort of function work in the current GUI method. I have read the tutorials on the current method but it mostly only covers static or user edited text, which doesnt help me unfortunately.
Your answer
Follow this Question
Related Questions
Pop up text from Floating text positioner interface c# 0 Answers
Move the text in a GUI Button/Box 1 Answer
GUI.label overlapping text 1 Answer
Gui Text Script 4 Answers
Alpha not working in GUITex 0 Answers