纳金网

标题: GUI里面图片的旋转(附带钟表例子) [打印本页]

作者: 王者再临    时间: 2014-4-30 23:46
标题: GUI里面图片的旋转(附带钟表例子)
 简单介绍一下代码

  GUIUtility.RotateAroundPivot (6*Time1, Vector2(103, 200))为旋转GUI的代码,第一个参数为旋转的角度,第二个参数为旋转的中心点,在它之下的GUI元素都会执行该旋转,例如图片、文字等。当你只想旋转某一GUI元素而其他元素不旋转事就得给它一个停止旋转的代码,很简单,停止旋转时给它一个反向的角度,ok。
  1. var Tu1 : Texture2D;

  2.   var Time1 : float = 0;

  3.   function FixedUpdate () {

  4.    Time1 += Time.deltaTime;

  5.   }

  6.   function OnGUI () {

  7.    GUI.Label(Rect(250,170,161,62),getTime(Time1));

  8.   

  9.    GUIUtility.RotateAroundPivot (6*Time1, Vector2(103, 200));

  10.    GUI.DrawTexture(Rect(100,100,6,100),Tu1);//秒针

  11.    GUIUtility.RotateAroundPivot (-6*Time1, Vector2(103, 200));

  12.   

  13.    GUIUtility.RotateAroundPivot (0.1*Time1, Vector2(103, 200));

  14.    GUI.DrawTexture(Rect(100,120,6,80),Tu1);//分针

  15.    GUIUtility.RotateAroundPivot (-0.1*Time1, Vector2(103, 200));

  16.   

  17.    GUIUtility.RotateAroundPivot (0.1/60*Time1, Vector2(103, 200));

  18.    GUI.DrawTexture(Rect(100,140,6,60),Tu1);//时针

  19.    GUIUtility.RotateAroundPivot (-0.1/60*Time1, Vector2(103, 200));

  20.   }

  21.    function getTime(time : float) : String{

  22.    if(time<0){

  23.    return "00:00:00";

  24.    }

  25.    var lastTime : String = "";

  26.    var hour = Mathf.FloorToInt(time/3600%24);

  27.    if(hour/10 >=1){

  28.    lastTime+="" + hour;

  29.    }else{

  30.    lastTime +="0" + hour;

  31.    }

  32.    var minute = Mathf.FloorToInt(time/60%60);

  33.    if(minute/10 >=1){

  34.    lastTime+=":" + minute;

  35.    }else{

  36.    lastTime +=":0" + minute;

  37.    }

  38.    var second = Mathf.FloorToInt(time%60);

  39.    if(second/10 >=1){

  40.    lastTime+=":" + second;

  41.    }else{

  42.    lastTime +=":0" + second;

  43.    }

  44.    return lastTime;

  45.   }
复制代码





欢迎光临 纳金网 (http://course.narkii.com/club/) Powered by Discuz! X2.5