unity3d怎么让方块上下滚动

2025-06-23 07:21:53
推荐回答(1个)
回答1:

自己建个Cube后将下面的脚本挂上去,运行,按键盘R键或T键看效果。

using UnityEngine;
using System.Collections;

public class Hello : MonoBehaviour {

    float rotate = 30.0f;
    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        if (Input.GetKey (KeyCode.R)) {
            transform.RotateAround (transform.position, Vector3.right, rotate);
        }

        if (Input.GetKey (KeyCode.T)) {
            transform.RotateAround (transform.position, Vector3.right, -rotate);
        }
    }

}