• 缩放 +旋转


    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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    python基础
    目标文件格式
    PHP 计算每个月的最后一天
    学习应该专注于学习这件事上
    以 Composer 的方式在 PhpStorm 中添加代码审查工具 Code Sniffer
    开始在博客园写文章啦!
    Git 常用操作
    常用写作格式
    将公司的主要项目从eclipse迁移到android studio for mac环境(1)
    写随笔、博客的心情
  • 原文地址:https://www.cnblogs.com/hpu001/p/10097874.html
Copyright © 2020-2023  润新知