Unity3d: How to do the rotation of the picture in the GUI

Source: Internet
Author: User

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; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.