没有合适的资源?快使用搜索试试~ 我知道了~
首页Unity3D实现物体旋转缩放移动效果
Unity3D实现物体旋转缩放移动效果
1.3k 浏览量
更新于2023-05-24
评论
收藏 55KB PDF 举报
主要为大家详细介绍了Unity3D实现物体旋转缩放移动效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
资源详情
资源评论
资源推荐

Unity3D实现物体旋转缩放移动效果实现物体旋转缩放移动效果
主要为大家详细介绍了Unity3D实现物体旋转缩放移动效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Unity3D实现物体旋转缩放移动的具体代码,供大家参考,具体内容如下
由于项目运行在安卓上,运用到了插件,比较麻烦。你们可以在触发条件上进行修改,不用插件也可以。
1.下载FingerGestures 插件 下载地址 点击打开链接
2.导入插件,创建场景 将预设Finger Gestures Initializer 拖拽到 Hierarchy 视图中
3.添加脚本,拖拽到摄像机上。创建一个方块拖拽到脚本target 属性上。
using UnityEngine;
using System.Collections;
public class ObjectControl : MonoBehaviour
{
public Transform target;
public float yawSensitivity = 80.0f;
public float pitchSensitivity = 160.0f;
public bool clampPitchAngle = true;
public float pinchZoomSensitivity = 0.5f;//缩放速度
public float smoothZoomSpeed = 10.0f;
public float smoothOrbitSpeed = 20.0f;
public float distance = 0;
float yaw = 0;
float pitch = 0;
float idealYaw = 0;
float idealPitch = 0;
float fChangeScale = 0;
float fChangeideal = 0;
public Transform[] movementP;
/// <summary>
/// 控制模式枚举
/// </summary>
public enum ControlModel
{
Zoom, Rotate, Translate
}
public ControlModel controlModel = ControlModel.Rotate;
//Vector3 position=new Vector3();
public bool bArrive = false;//鼠标是否到达零件箱边界区域
//平移方式是否根据鼠标拖动距离还是直接置为鼠标位置
public bool ifDragMove = false;
//平移方式为:根据鼠标拖动距离 时,评议的速度
public float moveSpeed = 1.0f;
//是够需要画出按钮(缩放、旋转、平移)
public bool ifDrawBtn = true;
//缩放方式改为:改变相机范围
public bool zoomCamera = false;
//zoomCamera = true ,相机的最小范围值
public float minZoom = 0f;
//zoomCamera = true ,相机的最大范围值
public float maxZoom = 179f;
//平移对象
public Transform moveTarget;
//平移对象的初始位置
Vector3 moveTargetPos;
//模型的直接父对象
public Transform parentModel;
Vector3 parentModelPos;
void Start()
{
zoomCamera = true;
}
void OnEnable()
{
FingerGestures.OnDragMove += FingerGestures_OnDragMove;
FingerGestures.OnPinchMove += FingerGestures_OnPinchMove;
FingerGestures.OnFingerDragEnd += OnFingerDragEnd;
}
void OnDisable()
{

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0