码迷,mamicode.com
首页 > 编程语言 > 详细

unity中2D与3D物体的线性检测

时间:2017-12-09 14:54:09      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:col   检测   arp   ast   点击   csharp   new   null   cas   

2D:

Vector2 mousePoint2D = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
 RaycastHit2D hitInfo2D = Physics2D.Raycast(mousePoint2D, Vector2.zero);
if (hitInfo2D.collider != null)
{
    Debug.Log(hitInfo2D.collider.name); //点击到的物体
}

3D:

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 RaycastHit hitInfo;
 if (Physics.Raycast(ray, out hitInfo))
{
    //点击到物体
}

  

 

unity中2D与3D物体的线性检测

标签:col   检测   arp   ast   点击   csharp   new   null   cas   

原文地址:http://www.cnblogs.com/lichuangblog/p/8011394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!