找回密码
 立即注册
查看: 6947|回复: 70

[脚本] Unity倒计时代码

[复制链接]
发表于 2012-11-12 15:22 | 显示全部楼层 |阅读模式

1、最简单的倒计时:
[code=javascript]var time_:int;
function Update()
{
   time_=100-Time.time;
  print(time_.ToString());
}[/code]

2、Unity3d GUI 时钟脚本
[code=javascript]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;
  }[/code]

评分

参与人数 1鲜花 +1 +1 收起 理由
zhaoqingqing + 1 + 1

查看全部评分

发表于 2017-3-21 10:40 | 显示全部楼层
楼主是超人
发表于 2017-3-21 10:31 | 显示全部楼层
真心顶
发表于 2017-3-21 11:19 | 显示全部楼层
难得一见的好帖
发表于 2017-3-21 10:51 | 显示全部楼层
说的非常好
发表于 2017-3-21 11:16 | 显示全部楼层
LZ真是人才
发表于 2017-4-4 15:37 | 显示全部楼层
好帖就是要顶
发表于 2017-4-4 16:14 | 显示全部楼层
顶顶多好
发表于 2017-4-4 16:24 | 显示全部楼层
真心顶
发表于 2017-4-4 15:29 | 显示全部楼层
说的非常好
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-22 01:16 , Processed in 0.239896 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表