Unity 3d角色展示脚本(旋转 平移 缩放)展示界面

不考虑性能 很简陋的一个功能,主要是用于角色渲染的观察用,比simplecontroller要好用一点

csharp 复制代码
using System;
using UnityEngine;

public class CharacterViewer : MonoBehaviour
{
    public Transform target; // 人物模型的Transform
    public float rotationSpeed = 5f;
    public float zoomSpeed = 1f;
    public float panSpeed = 0.001f;
    private Vector3 lastMousePosition;
    

    void Update()
    {
        // 旋转
        if (Input.GetMouseButton(0))
        {
            float mouseX = -Input.GetAxis("Mouse X");
            // float mouseY = Input.GetAxis("Mouse Y");
            target.Rotate(Vector3.up, mouseX * rotationSpeed, Space.World);
            // target.Rotate(Vector3.right, -mouseY * rotationSpeed, Space.Self);
        }

        // 缩放
        float scroll = Input.GetAxis("Mouse ScrollWheel");
        if (scroll != 0)
        {
            Vector3 zoomDirection = transform.forward;
            transform.position += zoomDirection * (scroll * zoomSpeed);
        }

        // 平移
        if (Input.GetMouseButtonDown(2))
        {
            lastMousePosition = Input.mousePosition;
        }
        if (Input.GetMouseButton(2))
        {
            Vector3 delta = Input.mousePosition - lastMousePosition;
            Camera.main.transform.Translate(-delta.x * panSpeed, -delta.y * panSpeed, 0);
            lastMousePosition = Input.mousePosition;
        }
    }
}
相关推荐
mifengxing18 小时前
LeetCode 41.缺失的第一个正数|Hard题O(n)+O(1)最优解法深度解析
java·算法·leetcode·排序算法
markinmarkin21 小时前
Spring 中Bean 的作用域有哪些?
java·后端·spring
山荷枝1 天前
Java学习第十天
java·学习
matlabgoodboy1 天前
计算机毕设代做|Java Python Matlab APP 全套开发设计
java·python·课程设计
DaLiangChen1 天前
Vuforia 地面识别案例
unity·ar
程序员雷欧1 天前
环形缓冲区深度解析:从基础原理到Disruptor源码的全面剖析
java
xiaoqiMikko1 天前
Dependabot 面板全绿,不代表你的 Tomcat 没洞
java·spring boot
前端开发张小七1 天前
Java 学习笔记 · 第三课:多线程与并发编程(线程、同步、死锁、Lock、乐观锁与悲观锁)
java·后端·程序员
花生了什么事o1 天前
JVM 垃圾回收:对象如何被判定和回收
java·jvm
evans在进步1 天前
HashMap 为什么线程不安全?ConcurrentHashMap 如何解决?
java·spring boot·spring