so the code I have made for my bullet is meant to destroy itself when it hits the player but right now it only goes through. I’m confused since I have collisions on for both the bullet and the player.
This is the code for the bullet
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D> ();
target = GameObject.FindObjectOfType<Player>();
moveDirection = (target.transform.position - transform.position).normalized * moveSpeed;
rb.velocity = new Vector2 (moveDirection.x, moveDirection.y);
Destroy (gameObject, 2f);
}
void OnTriggerEnter2D (Collider2D col)
{
if (col.gameObject.name.Equals ("Player")) {
Debug.Log ("Hit!");
Destroy (gameObject);
}
}
}