嗨,我尝试将gameObject旁边的行强制转换为gameObject

bool Valid(Vector3 direction)
{
    Vector3 position = transform.position;
    RaycastHit hit = Physics.Linecast (position + direction, direction);
    return (hit.collider == GetComponent<Collider>());
}


错误:


  无法隐式转换类型bool' to UnityEngine.RaycastHit'

最佳答案

如果在Physics.Linecaststart之间的线之间存在任何对撞机,则end返回true,但不返回RaycastHit

您必须添加hit变量作为第三个参数:

RaycastHit hit;
Physics.Linecast(position + direction, direction, out hit);


有关更多信息,请参见API

关于c# - 无法将类型'bool'隐式转换为'UnityEngine.RaycastHit',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29323335/

10-12 21:20