//射线原点
[SerializField] Transform tr;
//射线长度
[SerializField] float dis = 5;
//射线停留时间
[SerializField] float t=0.1f
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//显示射线
Ray ray = new Ray(tr.position,tr.forward) ;
RaycastHit hit;
Debug.DrawRay(tr.position, tr.forward * dis, Color.black, t);
if (Physics.Raycast(ray,out hit,100)) {
//检测特定名称对象
if (hit.collider.name== "Cube (1)") {
print("被射到了");
}
}
}