如何在Unity中将Raycast 3D转换为2D

时间:2017-05-09 17:33:02

标签: c# unity3d raycasting

我是Unity的初学者。我最近完成了团结的现场训练,即“Jewel Miner”(3D)。我尝试在2D中复制它,但在转换后它无法正常工作。

3D培训的原始代码:

    RaycastHit hit;
    Vector3 down = transform.TransformDirection(Vector3.down);

    if(Physics.Raycast(transform.position, down, out hit, 100))
    {
        claw.SetActive(true);
        clawScript.ClawTarget(hit.point);
    }

这是我转换的内容:

Vector2 down = transform.TransformDirection(Vector2.down);
RaycastHit2D hit = Physics2D.Raycast (new Vector2 (transform.position.x, transform.position.y), down, 100);

if(hit){
claw.SetActive(true);
clawScript.ClawTarget(hit.point);
}

0 个答案:

没有答案