我有一个问题,在光线投射,我的射线无法发现的球员,即使我做了分层面具,并去绘制射线和所有其他东西。但它仍然不起作用。

这是我的代码:
RaycastHit2D raycastHit2D = Physics2D.Raycast(enemyEyes.transform.position, new Vector2(directionOfRay, 0), LayerMask.GetMask("Player"));
if(raycastHit2D.collider != null )
{
if (raycastHit2D.collider.gameObject.tag=="Player")
{
Debug.Log("Hit Hit");
}
}
Debug.DrawRay(enemyEyes.transform.position,new Vector3(directionOfRay , 0,0) , Color.red);被击中的问题是没有显示在控制台中。
光线无法探测到我的玩家时的光线投射问题。
发布于 2022-10-29 18:09:12
玩家必须指定对撞机。试试这个:
RaycastHit2D hitObstacle = Physics2D.Raycast (obstacleRayObject.transform.position, Vector2.right, obstacleRayDistance, layerMask);
if (hitObstacle.collider != null) {
Debug.DrawRay (obstacleRayObject.transform.position, Vector2.right * hitObstacle.distance * new Vector2 (characterDirection, 0f), Color.red);
Debug.Log ("Object Detected");
} else {
Debug.DrawRay (obstacleRayObject.transform.position, Vector2.right * obstacleRayDistance * new Vector2 (characterDirection, 0f), Color.green);
}https://stackoverflow.com/questions/74247329
复制相似问题