纳金网
标题:
拖动物体的代码
[打印本页]
作者:
狂风大尉
时间:
2014-6-26 23:16
标题:
拖动物体的代码
var mouseOverColor = Color.blue;
private var originalColor : Color;
function Start () {
originalColor = renderer.sharedMaterial.color;
}
function OnMouseEnter () {
renderer.material.color = mouseOverColor;
}
function OnMouseExit () {
renderer.material.color = originalColor;
}
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;
}
}
复制代码
作者:
hyui
时间:
2014-6-26 23:46
Thanks for sharing this !
作者:
wucnj
时间:
2014-6-27 13:41
感谢分享!!!
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5