【问题标题】:Draw line on mouse move and detect line collision in Unity2D and Unity3D在 Unity2D 和 Unity3D 中绘制鼠标移动并检测线碰撞
【发布时间】:2014-12-15 19:45:35
【问题描述】:

我使用http://www.theappguruz.com/tutorial/draw-line-mouse-move-detect-line-collision-unity2d-unity3d/ 的线路碰撞代码,它工作正常。它检测线何时与自身发生碰撞,但我需要检查与其他对象的碰撞(比如说一个平台)。我在脚本中添加了这个函数:

private bool isLineCollidedWithOtherObject()
{
    RaycastHit hit;
    Ray ray = Camera.main.ScreenPointToRay(Camera.main.WorldToScreenPoint(pointsList[pointsList.Count-1]));
    if(Physics.Raycast(ray,out hit))
    {
          if(hit.collider)
          return true;
    }
    return false;
}

并在检查碰撞时添加

if(isLineCollide() && isLineCollidedWithOtherObject());

但它不起作用。我将Box2dcollider 添加到平台(播放器)。我做错了什么?

【问题讨论】:

    标签: android unity3d collision-detection


    【解决方案1】:

    看看这个帖子,特别是开发人员关于在 2d sprite 游戏中从 3d 空间中的相机进行光线投射的链接帖子:

    http://forum.unity3d.com/threads/unity-2d-raycast-from-mouse-to-screen.211708/#post-1424457

    提到的函数的文档在这里:http://docs.unity3d.com/ScriptReference/Physics2D.GetRayIntersection.html

    【讨论】:

      猜你喜欢
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多