Unity鼠标抓取gameobject(类似碰撞检测)

创建一个cube的go   绑定一个脚本代码:

using UnityEngine;
using System.Collections;

public class Mouse : MonoBehaviour
{
    Ray ray;
    RaycastHit hit;
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
                Debug.Log(hit.collider.gameObject.name);
        }
    }
}
posted @ 2012-08-02 11:52  Marble  阅读(2145)  评论(0编辑  收藏