纳金网

标题: 鼠标抓取gameobject(类似碰撞检测) [打印本页]

作者: 王者再临    时间: 2014-10-31 19:52
标题: 鼠标抓取gameobject(类似碰撞检测)

创建一个cube的go绑定一个脚本代码:
  1. using UnityEngine;
  2. using System.Collections;

  3. public class Mouse : MonoBehaviour
  4. {
  5.     Ray ray;
  6.     RaycastHit hit;
  7.     void Update()
  8.     {
  9.         if (Input.GetMouseButton(0))
  10.         //Unity3d:www.unitymanual.com
  11.         {
  12.             ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  13.             if (Physics.Raycast(ray, out hit))
  14.                 Debug.Log(hit.collider.gameObject.name);
  15.         }
  16.     }
  17. }
复制代码

作者: 我不再年轻    时间: 2014-10-31 20:26
简单好用,多谢!
作者: tianhett    时间: 2014-10-31 21:37
酱油一个。。。。
作者: hyui    时间: 2014-11-2 21:12
good code thakns!




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