纳金网

标题: 拖动物体的代码 [打印本页]

作者: 狂风大尉    时间: 2014-6-26 23:16
标题: 拖动物体的代码
  1. var mouseOverColor = Color.blue;
  2. private var originalColor : Color;
  3. function Start () {
  4. originalColor = renderer.sharedMaterial.color;
  5. }
  6. function OnMouseEnter () {
  7. renderer.material.color = mouseOverColor;
  8. }
  9. function OnMouseExit () {
  10. renderer.material.color = originalColor;
  11. }
  12. function OnMouseDown () {
  13. var screenSpace = Camera.main.WorldToScreenPoint(transform.position);
  14. var offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
  15. while (Input.GetMouseButton(0))
  16. {
  17.   var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
  18.   var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;
  19.   transform.position = curPosition;
  20.   yield;
  21. }
  22. }
复制代码

作者: 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