- 最后登录
- 2018-6-29
- 注册时间
- 2011-7-1
- 阅读权限
- 20
- 积分
- 359
- 纳金币
- 335582
- 精华
- 0
|
var myRect : Rect;
var myRectBG : Rect;
var myText : Texture;
var myTextBG : Texture;
var remainingTime : float;
var startTime = 60.0;
//(assuming you want to start with 60 seconds) //the width (in pixels) that represents one second
var WIDTH_PER_SECOND = 2;
function Start()
{
myRect = Rect(Screen.width / 2 - 256, Screen.height / 2-16 ,512,32);
myRectBG =Rect(Screen.width / 2 - 256, Screen.height / 2-16 ,512,32);
//begin with 'startTime' seconds on the clock remainingTime = startTime;
}
function Update()
{
remainingTime -= Time.deltaTime*5;
myRect.width = remainingTime * WIDTH_PER_SECOND;
if (myRect.width < 0)
{
myRect.width = 0;
}
}
function OnGUI()
{
//GUI.BeginGroup(Rect (Screen.width / 2 - 250, Screen.height / 2 - 50, 500, 100)); GUI.DrawTexture(myRect, myText);
GUI.DrawTexture(myRectBG , myTextBG);
}
function OnControllerColliderHit(hit:ControllerColliderHit)
{
if(hit.gameObject.tag == "gem")
{
Destroy(hit.gameObject); //add 5 seconds to the timer remainingTime += 50;
}
} |
|