[Unity3d鼠标拖拽物体]unity 鼠标拖拽物体.docx

上传人:啊飒飒 文档编号:14799157 上传时间:2022-02-20 格式:DOCX 页数:2 大小:17.40KB
返回 下载 相关 举报
[Unity3d鼠标拖拽物体]unity 鼠标拖拽物体.docx_第1页
第1页 / 共2页
[Unity3d鼠标拖拽物体]unity 鼠标拖拽物体.docx_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《[Unity3d鼠标拖拽物体]unity 鼠标拖拽物体.docx》由会员分享,可在线阅读,更多相关《[Unity3d鼠标拖拽物体]unity 鼠标拖拽物体.docx(2页珍藏版)》请在三一文库上搜索。

1、本文格式为Word版,下载可任意编辑Unity3d鼠标拖拽物体unity 鼠标拖拽物体 爱学习的小伙伴们,可能都有了解过Unity3d ,但是你知道Unity3d 怎么使用鼠标拖拽物体吗? Unity3d使用鼠标拖拽物体的详细代码 /Drag object using mouse /editor by faye euler /add script components to the collider Object with need to be draging /將代碼附加到要被拖拽的collider物體上 function Update () var screenSpace; var off

2、set; function OnMouseDown() /translate the cubes position from the world to Screen Point /轉換對象位置,從世界點到屏幕座標 screenSpace = Camera.main.WorldToScreenPoint(transform.position); /calculate any difference between the cubes world position and the mouses Screen position converted to a worldpoint /在對象世界座標與鼠標

3、屏幕座標計算任何不同,轉換到世界點上 offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y, screenSpace.z); /* OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse. OnMouseDrag is called every frame w

4、hile the mouse is down. */ function OnMouseDrag () /keep track of the mouse position /保持鼠標位置追蹤 var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); /convert the screen mouse position to world point and adjust with offset /轉換屏幕鼠標位置到世界點,以及通過偏移調整 var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset; /update the position of the object in the world /更新物體在世界的位置 transform.position = curPosition; 猜你喜爱: 1.2021程序员跳槽全攻略 2.2021有什么好玩的手机嬉戏 3.创业,我们的故事 4.如何从零开头创业 5.90后创业心得第 2 页 共 2 页

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1