模型展示;
创建个rendertexture 调整分辨率 然后设置给用于渲染展示模型的相机(相机layer只需要模型的比如model)
在UI上创建一个rawimage 吧texture属性指定为 刚才创建的rendertexture
给rawiamge添加如下脚本,设置如上图
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class RotateCam : MonoBehaviour,IDragHandler
{
private Vector2 startPos;
public Vector3 centerPos;
public Transform camParent;
public float Angle = 30;
public float minOffset=10;
public Transform cameraTr;
public float ZoomSpeed;
public void OnDrag(PointerEventData eventData)
{
Vector2 offset = eventData.position - startPos;
if (Mathf.Abs(offset.x) > minOffset)
{
camParent.Rotate(Vector3.up * Angle * offset.normalized.x, Space.World);
}
else if (Mathf.Abs(offset.y) > minOffset)
{
camParent.Rotate(Vector3.forward * Angle * offset.normalized.y, Space.Self);
}
startPos = eventData.position;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float zoom = Input.GetAxis("Mouse ScrollWheel");
//if (Mathf.Abs(zoom) < minOffset) return;
cameraTr .Translate(Vector3.forward * zoom * Time.deltaTime * ZoomSpeed);
}
}
相机有个父物体 吧该物体设置为模型几何中心位置
调整相机到合适位置作为初始位置
运行即可实现相机拉进拉远 旋转查看