• 缩放 +旋转


    sing UnityEngine;

    public class FllowPlayer : MonoBehaviour
    {
    private Transform player;
    private Vector3 offsetPosition;
    public float scrollSpeed = 10;
    public float rotateSpeed = 5;
    private float distance;
    private bool isRotating = false;
    void Awake()
    {
    player = GameObject.FindGameObjectWithTag(Tags.Player).transform;
    }
    void Start()
    {
    offsetPosition = transform.position - player.position;
    transform.LookAt(player.position);
    ;
    }

    void Update()
    {
    transform.position = player.position + offsetPosition;
    //鼠标放大和缩放界面
    ScrollView();
    //旋转界面
    RotateView();

    }

    //放大和缩放界面
    private void ScrollView()
    {
    distance = offsetPosition.magnitude;
    distance -= Input.GetAxis("Mouse ScrollWheel") * scrollSpeed;
    distance = Mathf.Clamp(distance, 3, 15);
    offsetPosition = offsetPosition.normalized * distance;
    }

    //按鼠标右键旋转界面
    private void RotateView()
    {
    if (Input.GetMouseButtonDown(1))
    {
    isRotating = true;
    }
    if (Input.GetMouseButtonUp(1))
    {
    isRotating = false;
    }
    if (isRotating)
    {
    //左右旋转
    transform.RotateAround(player.position, player.up, Input.GetAxis("Mouse X") * rotateSpeed);
    Vector3 origionPosition = transform.position;
    Quaternion origionRotation = transform.rotation;
    //上下旋转
    transform.RotateAround(player.position, transform.right, -Input.GetAxis("Mouse Y") * rotateSpeed);
    float x = transform.eulerAngles.x;
    if (x < 30 || x > 80)
    {
    transform.position = origionPosition;
    transform.rotation = origionRotation;
    }
    offsetPosition = transform.position - player.position;
    }
    }
    }
    ---------------------
    作者:cchoop
    来源:CSDN
    原文:https://blog.csdn.net/qq_34937637/article/details/81238375
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    《APP》团队冲刺第二阶段 八
    《APP》团队冲刺第二阶段 七
    《APP》团队冲刺第二阶段 六
    《APP》团队冲刺第二阶段 五
    《APP》团队冲刺第二阶段 四
    团队项目总结(事后诸葛亮)
    第二阶段团队效绩
    团队项目-第二阶段冲刺-10
    团队项目-第二阶段冲刺-9
    团队项目-第二阶段冲刺-8
  • 原文地址:https://www.cnblogs.com/hpu001/p/10097874.html
Copyright © 2020-2023  润新知