纳金网
标题:
GUI里面图片的旋转(附带钟表例子)
[打印本页]
作者:
王者再临
时间:
2014-4-30 23:46
标题:
GUI里面图片的旋转(附带钟表例子)
简单介绍一下代码
GUIUtility.RotateAroundPivot (6*Time1, Vector2(103, 200))为旋转GUI的代码,第一个参数为旋转的角度,第二个参数为旋转的中心点,在它之下的GUI元素都会执行该旋转,例如图片、文字等。当你只想旋转某一GUI元素而其他元素不旋转事就得给它一个停止旋转的代码,很简单,停止旋转时给它一个反向的角度,ok。
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;
}
复制代码
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5