如何使用RayCast2D销毁子弹?

时间:2019-05-08 17:52:31

标签: c# unity3d raycasting

我的游戏弹丸太快了;一些子弹穿过对撞机。

我进行了RayCast的射线检测对撞机,它正在工作。我在尝试进行RayCast2D来摧毁子弹撞到对撞机时遇到麻烦。

if (Input.GetButtonDown("Fire1") && Time.time > nextfire)
{
    nextfire = Time.time + firerate;
    anim.SetTrigger("Shoot");
    GameObject tempBullet = Instantiate(bulletPrefab, shotSpawner.position, 
        shotSpawner.rotation);
    RaycastHit2D hit = Physics2D.Raycast(shotSpawner.position, shotSpawner.right);
    Debug.DrawLine(transform.position, transform.right * 300f, Color.cyan);

    if (hit.collider.tag != null)
    {
        nextfire = Time.time;
        print(hit.collider.name);
    }
    else
    {
        print(hit.collider.name);    
    }
}

0 个答案:

没有答案