unity 控制物体旋转的角度

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Main : MonoBehaviour
{
    
    public float speed;
    private float yCout;
    private float yLastCout;
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("开始");
    }

    // Update is called once per frame
    void Update()
    {
        //Debug.Log("循环");

      if (Input.GetMouseButton(0))
        {
            //Debug.Log("按下鼠标");
            float  xValue = -speed * Input.GetAxis("Mouse X");
            float  yValue = speed * Input.GetAxis("Mouse Y");
            yCout += yValue;
            yCout = Mathf.Clamp(yCout, xMinLimit, xMaxLimit);
           float realYValue = yCout - yLastCout;
            transform.Rotate (Vector3.up, xValue);
            transform.Rotate (Vector3.right, realYValue, Space.World);
            yLastCout = yCout;

          }        
       }       
    }

猜你喜欢

转载自blog.csdn.net/m0_62316260/article/details/127426762