unity中手指选中物体拖动旋转
来源:互联网 发布:python vim 编辑:程序博客网 时间:2024/05/05 02:57
小Demo测试~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
如上图,运行游戏时,点击cube物体,左右拖动进行旋转。在cube上使用脚本DragRotate。
脚本内容如下:
using UnityEngine;
using System.Collections;
public class DragRotate : MonoBehaviour {
public Camera m_Camera;
public GameObject m_Cube;
private bool isDragging = false;
private float m_lastMouseX = float.MaxValue;
private float m_lastSpeed = 0f;
private bool m_isMoving = false;
// Use this for initialization
void Start () {
}
void FixedUpdate()
{
if(this.m_isMoving){
this.m_lastSpeed *= 0.9f;//递减
Vector3 localEulerAngles = m_Cube.transform.localEulerAngles;
m_Cube.transform.localEulerAngles = new Vector3(localEulerAngles.x, localEulerAngles.y -= m_lastSpeed*0.5f, localEulerAngles.z);
if(Mathf.Abs(this.m_lastSpeed) < 0.01)
{
this.m_isMoving = false;
}
}
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0)){
if (m_Camera != null)
{
RaycastHit hit;
Ray m_ray = m_Camera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(m_ray,out hit, 1000f, m_Camera.cullingMask) && (hit.collider.gameObject == base.gameObject))
{
//选中物体
Debug.Log("选中物体");
this.isDragging = true;
}
}
}
else if(Input.GetMouseButtonUp(0))
{
//抬起
this.isDragging = false;
//抬起后缓慢转动
this.m_isMoving = true;
this.m_lastSpeed = Input.mousePosition.x - this.m_lastMouseX;
this.m_lastMouseX = float.MaxValue;
}
if (this.isDragging)
{
float num = 0;
if (this.m_lastMouseX != float.MaxValue)
{
num = Input.mousePosition.x - this.m_lastMouseX;
}
this.m_lastMouseX = Input.mousePosition.x;
Vector3 cube_localEulerAngles = m_Cube.transform.localEulerAngles;
m_Cube.transform.localEulerAngles = new Vector3(cube_localEulerAngles.x, cube_localEulerAngles.y -= num * 0.5f, cube_localEulerAngles.z);
}
}
}
- unity中手指选中物体拖动旋转
- 【unity】Unity 手指滑动让物体旋转
- Unity 拖动鼠标物体旋转
- Unity中实现鼠标拖动旋转物体和鼠标点击旋转物体
- unity 手指移动物体旋转两个手指控制物体大小缩放
- unity 手指旋转物体双手控制相机的远近
- UNITY手指接触屏幕对物体进行旋转和缩放
- Vuforia在Unity中屏幕坐标转世界坐标,并使用lineRender画线,手指画线,选中物体并拖拽
- unity 3d中简单巧妙的实现拖动鼠标旋转物体
- Unity3D 拖动物体旋转
- [Unity3d]旋转拖动物体
- Unity3d旋转拖动物体
- Unity3D 拖动物体旋转
- unity中根据鼠标移动旋转物体
- Unity物体拖动
- Unity拖动物体代码
- Unity 拖动UI物体
- Unity 物体拖动
- sqlite中的virtual表之空间索引
- tail和ls的使用, bash-completion的安装和使用
- Auto property synthesis will not synthesize property 'description' because it is 'readwrite' but it
- dede搜索页面的问题{dede:hotwords /}参数说明:num=’5′ 关键词数目 subday=’100′ 天数 maxlength=’32′ 关键词最大长度 在很多时候,搜索
- LevelDB 存储编码
- unity中手指选中物体拖动旋转
- Windows中句柄和ID的区别
- WeOnlyDo.Server服务器介绍
- javascript/JS限制用户名只能输入 汉字字母和数字下划线
- 页面Sql语句 查询根据判断值是否存在拼接查询条件
- Crontab 定时任务
- Java线程的wait() 与notify()
- linux zip 文件夹
- Window下Qt4.8.4与Mysql5.5.28 驱动生成(mingw)