Guiutility.rotatearoundpivot (6*time1, Vector2 (103, 200)) is the code that rotates the GUI, the first parameter is the angle of rotation, the second parameter is the center of rotation, and the GUI element underneath it performs the rotation. such as pictures, text, and so on. When you just want to rotate a GUI element and the other element does not rotate, you have to give it a stop-spinning code. Use the picture rotation to write the code for a clock as follows:
For ease of testing, give a digital time on the left side of the clock to compare the rows. GetTime (time:float) can be used to achieve the display of time in the scene, or the display of the countdown.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/
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);//Second hand guiutility.rotatearoundpivot ( -6*time1, Vector2 (103, 200));
Guiutility.rotatearoundpivot (0.1*time1, Vector2 (103, 200)); Gui.
Drawtexture (Rect (100,120,6,80), Tu1);//minute hand 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);/clockwise Guiutility.rotatearoundpivot ( -0.1/60*time1, Vector2 (103, 200)); Unity3d Tutorial Manual function GetTime (time:float): string{if (time<0) {retur
n "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; }