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;
        }
    }
}
相关推荐
m0_748256143 小时前
SpringBoot
java·spring boot·后端
阿华的代码王国4 小时前
【从0做项目】Java搜索引擎(3)
java·搜索引擎·项目
Mr.朱鹏4 小时前
针对Feign客户端请求体参数处理问题
java·jvm·spring boot·spring·spring cloud·maven·intellij-idea
涛粒子6 小时前
Spring Bean 生命周期的执行流程
java·后端·spring
刘_sy6 小时前
使用EasyExcel和多线程实现高效数据导出
java·excel·easyexcel·批量导出excel
梦幻通灵6 小时前
IDEA通过Contince接入Deepseek
java·ide·intellij-idea
web150850966416 小时前
SQL 建表语句详解
java·数据库·sql
工业3D_大熊6 小时前
HOOPS Web Platform:3D模型轻量化与可视化的高效解决方案
3d·3d web轻量化·3d建模·3d模型轻量化·3d数据格式转换·工业3d·几何建模
xiangxiongfly9157 小时前
Java 设计模式之迭代器模式
java·设计模式·迭代器模式
FLZJ_KL7 小时前
【设计模式】【行为型模式】迭代器模式(Iterator)
java·设计模式·迭代器模式