Unity3d GUI 时钟脚本(js)

2016-11-10 10:32
371
 var Tu1 : Texture2D;
  var Time1 : float = 0;
  function FixedUpdate () {
   Time1 += Time.deltaTime;
  }
  function OnGUI () {
   GUI.Label(Rect(250,170,161,62),getTime(Time1));

   GUIUtility.RotateAroundPivot (6*Time1, Vector2(103, 200));
   GUI.DrawTexture(Rect(100,100,6,100),Tu1);//秒针
   GUIUtility.RotateAroundPivot (-6*Time1, Vector2(103, 200));

   GUIUtility.RotateAroundPivot (0.1*Time1, Vector2(103, 200));
   GUI.DrawTexture(Rect(100,120,6,80),Tu1);//分针
   GUIUtility.RotateAroundPivot (-0.1*Time1, Vector2(103, 200));

   GUIUtility.RotateAroundPivot (0.1/60*Time1, Vector2(103, 200));
   GUI.DrawTexture(Rect(100,140,6,60),Tu1);//时针
   GUIUtility.RotateAroundPivot (-0.1/60*Time1, Vector2(103, 200));
  }
   function getTime(time : float) : String{
   if(time<0){
   return "00:00:00";
   }
   var lastTime : String = "";
   var hour = Mathf.FloorToInt(time/3600%24);
   if(hour/10 >=1){
   lastTime+="" + hour;
   }else{
   lastTime +="0" + hour;
   }
   var minute = Mathf.FloorToInt(time/60%60);
   if(minute/10 >=1){
   lastTime+=":" + minute;
   }else{
   lastTime +=":0" + minute;
   }
   var second = Mathf.FloorToInt(time%60);
   if(second/10 >=1){
   lastTime+=":" + second;
   }else{
   lastTime +=":0" + second;
   }
   return lastTime;
  }

收藏
1 条回帖
LV.22016-11-10 16:11
顶一个!大家相互学习,哈哈!
需要登陆后才可进行回复 登录

返回顶部
现在加入我们,注册一个账号 账号登陆 QQ账号登陆 微博账号登陆

微信扫一扫,马上找工作

在线客服