不考慮性能 很簡陋的一個(gè)功能,主要是用于角色渲染的觀察用,比simplecontroller要好用一點(diǎn)文章來源地址http://www.zghlxwxcb.cn/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()
{
// 旋轉(zhuǎn)
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;
}
}
}
文章來源:http://www.zghlxwxcb.cn/news/detail-675195.html
到了這里,關(guān)于Unity 3d角色展示腳本(旋轉(zhuǎn) 平移 縮放)展示界面的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!