- Home /
Question by
rondonron · Oct 16, 2014 at 06:54 PM ·
javascriptrepeatbutton
RepeatButton with new UI Button in Javascript
So before Unity 4.6 I used a GUI button that when held down a timer would count up.
Here is My old code
var counter: int = 0;
var Timer = 0.0;
var gameText: GUIText;
var btnStyle:GUIStyle;
var backGround:GUIStyle;
function Start(){
gameText = gameObject.GetComponent(GUIText);
}
function OnGUI () {
GUI.Box (Rect (100,100,200,300), "Hold IT", backGround);
if (GUI.RepeatButton(new Rect(50,50,100,110),"", btnStyle)) {
counter++;
Timer += Time.deltaTime;
var hours : int = Timer / 3600;
var minutes : int = Timer / 60;
var seconds : int = Timer % 60;
var fraction : int = (Timer * 100) % 100;
gameText.text = String.Format ("{0:00}:{1:00}:{2:00}:{3:00}", hours, minutes, seconds, fraction);
}
}
So i thought id give the new UI button a try. I put this code on the button so when you hold it down it would start a timer. But I dont know how I can use the RepeatButton function with the new UI Button.
#pragma strict
var counter: int = 0;
var Timer = 0.0;
var gameText:UI.Text;
function Start(){
gameText = GetComponent(UI.Text);
}
function Update () {
counter++;
Timer += Time.deltaTime;
var hours : int = Timer / 3600;
var minutes : int = Timer / 60;
var seconds : int = Timer % 60;
var fraction : int = (Timer * 100) % 100;
gameText.text = String.Format ("{0:00}:{1:00}:{2:00}:{3:00}", hours, minutes, seconds, fraction);
}
How will the RepeatButton work ?? Do I still have to use function OnGUI() for it to work?
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to make a selection system? 1 Answer
How to spawn objects in a specific range of random location 1 Answer