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;
        }
    }
}
相关推荐
WX-bisheyuange1 小时前
基于Spring Boot的民宿预定系统的设计与实现
java·spring boot·后端·毕业设计
码界奇点1 小时前
Java设计模式精讲从基础到实战的常见模式解析
java·开发语言·设计模式·java-ee·软件工程
q***9443 小时前
springboot接入deepseek深度求索 java
java·spring boot·后端
诗9趁年华3 小时前
深入分析线程池
java·jvm·算法
百***06013 小时前
SpringBoot的@Scheduled和@Schedules有什么区别
java·spring boot·spring
喵了几个咪3 小时前
使用Bazel构建你的Kratos微服务
java·运维·微服务
点PY3 小时前
TR3D: Towards Real-Time Indoor 3D Object Detection论文精读
人工智能·目标检测·3d
千寻技术帮3 小时前
50022_基于微信小程序同城维修系统
java·mysql·微信小程序·小程序·同城维修
野蛮人6号3 小时前
黑马八股笔记
java
Charles_go4 小时前
41、C#什么是单例设计模式
java·设计模式·c#