2013-10-17 113 views
0

我想旋轉一個Unity按鈕。這是我的代碼,但它不起作用。旋轉統一按鈕

if (GUI.Button(
     new Rect(95 * Screen.width/100 - Screen.height/8, 
       4 * Screen.height/5, 
       Screen.height/4, 
       Screen.height/4), 
     MoreUp) || this.ForceMoreClick) 
{ 
    this.transform.rotation.x = 10f; 
    this.PlayMenuButtonClick(); 

    this.MoreAnimatedDir = this.MoreAnimatedDir == AnimatedDirection.UP 
     ? AnimatedDirection.UPREVERT 
     : AnimatedDirection.UP; 

    this.moreAnimation.ChangeAnimatedDirection(this.MoreAnimatedDir); 
    this.ForceMoreClick = false; 
} 

我必須爲此使用TweenLean嗎?

+2

要在Unity的直接模式GUI中旋轉單個元素,您需要操作GUI.matrix(RotateAroundPivot旋轉整個GUI)(http://docs.unity3d.com/Documentation/ScriptReference/GUI-matrix。如果你真的想經常旋轉GUI元素,我建議使用一個所見即所得的GUI工具包,比如NGUI或2D Toolkit,它們有點貴,但是,考慮你的時間值多少錢 – Calvin

回答

1

我發現這個代碼一點,將旋轉上點擊按鈕:

using UnityEngine; 
using System.Collections; 

    public class RotateButton: MonoBehaviour { 
     private float rotAngle = 0; 
     private Vector2 pivotPoint; 
     void OnGUI() { 
      pivotPoint = new Vector2(Screen.width/2, Screen.height/2); 
      GUIUtility.RotateAroundPivot(rotAngle, pivotPoint); 
      if (GUI.Button(new Rect(Screen.width/2 - 25, Screen.height/2 - 25, 50, 50), "Rotate")) 
       rotAngle += 10; //This is rotating it 10 degrees. 

     } 
    } 

或許它會幫助你。 來源:http://docs.unity3d.com/Documentation/ScriptReference/GUIUtility.RotateAroundPivot.html

+0

它不起作用 – gorgi93

+0

有沒有任何錯誤或者它只是不工作... – JLott

+0

它只是不設置按鈕旋轉它正在工作只是不旋轉 – gorgi93