日期:2014-05-16  浏览次数:20314 次

Unity3d 鼠标拾取 javascript
 function Update ()     
 {    
    if (Input.GetMouseButton (0))     
      {    
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);    
        var hit : RaycastHit;    
         if (Physics.Raycast (ray, hit))     
         {    
             Debug.DrawLine (ray.origin, hit.point);    
             print(hit.collider.gameObject.name);    
        }    
     }    
 } 

通过射线碰撞来实现,代码比较简单。