不考虑性能 很简陋的一个功能,主要是用于角色渲染的观察用,比simplecontroller要好用一点文章来源地址https://www.toymoban.com/news/detail-675195.html
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;
}
}
}
文章来源:https://www.toymoban.com/news/detail-675195.html
到了这里,关于Unity 3d角色展示脚本(旋转 平移 缩放)展示界面的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!