using UnityEngine;

public class NewBehaviourScript : MonoBehaviour 
{
    private Vector3 nowPos;
    private Vector3 oldPos;
    private bool isClick = false;
    public float length = 1;
    private void OnMouseUp()
    {
        isClick = false;
    }
    private void OnMouseDown()
    {
        isClick = true;
    }
    private void Update()
    {
        nowPos = Input.mousePosition;
        if(isClick ==true  )
        {
            Vector3 offset = nowPos - oldPos;
            if(Mathf .Abs (offset .x)>Mathf .Abs (offset .y )&&Mathf .Abs (offset .x )> length)
            {
                transform.Rotate(Vector3.up, -offset.x);
            }
        }
        oldPos = Input.mousePosition;
    }
}

将此脚本挂在Cube上(Cube一定要有碰撞器)

Unity中控制人物的旋转Unity中控制人物的旋转

 

相关文章:

  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2021-09-08
  • 2021-10-16
相关资源
相似解决方案