旋转统一按钮

时间:2013-10-17 15:49:02

标签: c# unity3d

我想旋转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?

1 个答案:

答案 0 :(得分: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