子弹穿过玩家

我使用团结,当敌人射击时,子弹直接穿过玩家。我不知道该怎么解决。这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyBullet : MonoBehaviour
{
public float speed;
public Rigidbody2D rb;
private Transform player;
private Vector2 target;
private Vector2 moveDirection;


// Start is called before the first frame update
void Start()
{
    player = GameObject.FindGameObjectWithTag("Player").transform;
    moveDirection = (player.transform.position - transform.position).normalized * speed;

}

// Update is called once per frame
void Update()
{
    rb.velocity = new Vector2(moveDirection.x, moveDirection.y);
    //transform.position = Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime);

}

void OnCollisionEnter2D(Collision2D other) {
    if (other.gameObject.tag == "Player") {
        Destroy(this.gameObject);
    }
}

}

我在子弹上放了一个名为BulletEnemy的标签,但它不起作用

评论