模型显示在ui上时滑动显示区域实现旋转
程序员文章站
2022-06-15 23:11:08
using UnityEngine;using UnityEngine.EventSystems;/// /// 在某个ui范围内旋转3D物体(挂在谁身上在谁的范围内)/// public class SpinWithMouse : MonoBehaviour, IDragHandler{ /// /// 要旋轉的三維物體的Transform組件 ///
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// 在某个ui范围内旋转3D物体(挂在谁身上在谁的范围内)
/// </summary>
public class SpinWithMouse : MonoBehaviour, IDragHandler
{
/// <summary>
/// 要旋轉的三維物體的Transform組件
/// </summary>
public Transform target;
/// <summary>
/// 旋转速度
/// </summary>
public float speed = 1f;
void Start()
{
if (target == null) target = transform;
}
public void OnDrag(PointerEventData eventData)
{
// 控制上下移动的旋转(不需要可设为0) 控制左右移动时的旋转
target.localRotation = Quaternion.Euler(0.5f * eventData.delta.y * speed, -0.5f * eventData.delta.x * speed, 0f) * target.localRotation;
}
}
本文地址:https://blog.csdn.net/weixin_43535270/article/details/109242707
下一篇: 2020做什么副业在家就能月入1W?