我的游戏弹丸太快了;一些子弹穿过对撞机。
我进行了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);
}
}