鼠标控制物体原地旋转

 

 

using UnityEngine;
using System.Collections;

public class MoveSphereScript : MonoBehaviour
{
    private float speed = 300.0f;

    void Start()
    {

    }

    void Update()
    {
        float x = 0, y = 0;
        if (Input.GetMouseButton(0))
        {
            //鼠标按着左键移动 
            y = Input.GetAxis("Mouse X") * Time.deltaTime * speed;
            x = Input.GetAxis("Mouse Y") * Time.deltaTime * speed;
        }

        Debug.Log(x + ", " + y);
        //旋转角度(增加)
        transform.Rotate(new Vector3(x, -y, 0), Space.World);
    }
}

完成

猜你喜欢

转载自blog.csdn.net/weixin_41814169/article/details/86303528