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;
        }
    }
}
相关推荐
.生产的驴16 分钟前
SpringBoot 接口国际化i18n 多语言返回 中英文切换 全球化 语言切换
java·开发语言·spring boot·后端·前端框架
Howard_Stark20 分钟前
Spring的BeanFactory和FactoryBean的区别
java·后端·spring
饮长安千年月21 分钟前
学生管理系统审计
java·网络安全·代码审计
-曾牛29 分钟前
Spring Boot中@RequestParam、@RequestBody、@PathVariable的区别与使用
java·spring boot·后端·intellij-idea·注解·spring boot 注解·混淆用法
weixin_4239950031 分钟前
unity 读取csv
unity·c#
GISBox32 分钟前
零基础教学:用GISBox将RVT转为3DTiles
3d
新时代苦力工41 分钟前
处理对象集合,输出Map<String, Map<String, List<MyObject>>>格式数据,无序组合键处理方法
java·数据结构·list
niesiyuan0001 小时前
MAC如何安装多版本jdk(以8,11,17为例)
java
zcyf08091 小时前
kafka理论学习汇总
java·分布式·学习·kafka
再拼一次吧1 小时前
Spring进阶篇
java·后端·spring