我试图从一个实例化的导弹预制件中投射一个2D射线,如下所示:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMissile : MonoBehaviour {
void Update () {
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down,1f);
Debug.DrawRay(transform.position, Vector2.down, Color.green);
if(hit)
{
print("Hit");
}
else
{
print("No hit");
}
}
}
不过,我看到控制台上什么也没印
我看到:
Raycast Hit Collider is Always NULL
Physics2D.Raycast returning null
谢谢你的帮助。
编辑
回答@Monofuse评论:当我选择玩家时,转换是:
x:0.4567,y:-1.58,z:0
当我选择导弹时,变换是:
x:0.3699,y:-1.054,z:0
编辑回答@Ada Nub:
我默认选中了这两个选项:查询命中触发器,查询在碰撞器中启动。
现在我在Colliders中启动了未选中的查询,但是结果是相同的,我在控制台上看不到打印:
现在它工作了: