美文网首页
3D情况下鼠标右击自由旋转

3D情况下鼠标右击自由旋转

作者: 咆哮的小老虎 | 来源:发表于2018-12-28 16:17 被阅读0次

    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    public class mrscroll : MonoBehaviour {

        public float rotateSpeed = 100;      //设置旋转的速度

        public Transform PlayerTrans;      //设置空物体的位置

        public float maxh = 10;              //设置提升的最高高度

        public Transform cam;

        Vector3 startPoint;

        Vector3 endPoint;

    void Start () {

                PlayerTrans.position = PlayerTrans.position + new Vector3(0, maxh, 0);//提升空物体的位置,后面做旋转范围用}

            }

            // Update is called once per frame

            void Update () {

            if (Input.GetMouseButtonDown(1))

            {

                startPoint = Input.mousePosition;

            }

            if (Input.GetMouseButton(1))

            {

                endPoint = Input.mousePosition;

                if (startPoint==endPoint)

                {

                    return;

                }

                if (endPoint.x-startPoint.x>0)

                {

                    cam.Rotate(Vector3.up);

                }

                else

                {

                    cam.Rotate(Vector3.down);

                }

                if (endPoint.y - startPoint.y > 0)

                {

                    cam.Rotate(Vector3.left);

                }

                else {

                    cam.Rotate(Vector3.right);

                }

                startPoint = endPoint;

            }

    }

    }

    相关文章

      网友评论

          本文标题:3D情况下鼠标右击自由旋转

          本文链接:https://www.haomeiwen.com/subject/cycelqtx.html