|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729340
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2015/1/20 9:16 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15771
|
- [轉貼]Unity 3d Countdown Timer
- Countdown Timer
Hey I need help
I would like a timer for my game but its like a game show timer so like say you have 3 mins to complete something then when 10 secs are left the timer comes up on the screen i would like something like that but i have no idea how to do it guitimer
check my answer on this question : http://answers.unity3d.com/questions/279434/problem-restart-time-by-key.html and this : http://answers.unity3d.com/questions/231521/how-to-display-data-in-an-array.html all the information you need to do this are in those 2 answers =] also : http://lmgtfy.com/?q=unity+countdown+timer EDIT : here is what you're after ....
#pragma strict
var theTimer : float = 0.0;
var theStartTime : float = 120.0;
var showRemaining : boolean = false;
function Start()
{
theTimer = theStartTime;
}
function Update()
{
theTimer -= Time.deltaTime;
if (theTimer < 10)
{
Debug.Log("TEN SECONDS LEFT !");
showRemaining = true;
}
if (theTimer <= 0)
{
Debug.Log("OUT OF TIME");
theTimer = 0;
}
if ( Input.GetKeyUp(KeyCode.G) )
{
Debug.Log("Resetting");
theTimer = theStartTime;
showRemaining = false;
}
}
function OnGUI()
{
var text : String = String.Format( "{0:00}:{1:00}", parseInt( theTimer / 60.0 ), parseInt( theTimer % 60.0 ) );
if (showRemaining)
{
GUI.Label( Rect( 10, 10, Screen.width - 20, 30), text );
}
}
Thats not what im looking for i have a script for a menu to come up but i need a script so it say 10 seconds left then starts counting down Jul 21, 2012 at 10:26 PM dalekandjedi
var showRemaining : boolean = false;
... in update
if (remainingTime < 10secs)
{
showRemaining = true;
}
... OnGUI
if (showRemaining)
{
GUI.Box( Rect(0,0,100,20), remainingTime.ToString() );
}
原文出處: Countdown Timer - Unity Answers
|
|
|
討論串
|