纳金网

标题: 拖拽物体的脚本 [打印本页]

作者: yeu1233    时间: 2012-8-27 16:10
标题: 拖拽物体的脚本
function OnMouseDown () {

var screenSpace = Camera.main.WorldToScreenPoint(transform.position);

var offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));

while (Input.GetMouseButton(0))

{

var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);

var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;

transform.position = curPosition;

yield;

}

}

作者: 王者再临    时间: 2012-12-30 04:34
学习了,虽然还是有难度,谢谢楼主的用心




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5