unity 3d 鼠标力度控制物体随意旋转

using UnityEngine;
using System.Collections;


public class player : MonoBehaviour {
    Vector3 zhou;
    float speed;
   GameObject   cube;
    float mouse_x;
    float mouse_y;
    Vector3 currentMouse;
    float drag = 0.2f;
    float scaleFactor = 7;
   
void Start () {
        cube=GameObject.Find("cube");
}
void Update () {
        if (Input.GetMouseButton(0))
        {
            mouse_x = Input.GetAxis("Mouse X");
            mouse_y = Input.GetAxis("Mouse Y");
            currentMouse = new Vector3(mouse_x, mouse_y, 0);
            zhou = Vector3.Cross(currentMouse, Vector3.forward);
            speed = Vector3.Magnitude(currentMouse) * scaleFactor;     
        }
        else {
            speed = Mathf.Clamp(speed - drag, 0, Mathf.Infinity);
        }
        cube.transform.Rotate(zhou, speed, Space.World);
}
}
阅读更多
下一篇unity3d 鼠标控制物体上下、左右、旋转
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭