Hi , im fairly new at Unity and last night i tried to create a bullet script that would
Destroy itself on impact
Deal damage to Player
But , even though the bullets collide with the Player, the OnCollisionEnter doesnt work.
Here is my script,
public class collision : MonoBehaviour {
PlayerHealth playerHealth;
public int bulletDamage;
public bool bulletHit;
void OnCollisionEnter2D (Collision2D col)
{
if (col.gameObject.tag == "Player" )
{
playerHealth.TakeDamage(bulletDamage);
Destroy(gameObject);
bulletHit = true;
}
}
}
I have no problems with my bullets being ejected. Heres some screenshots of bullets colliding with a collider and rigidbody
edit: my main players tag is definitely Player , bulletHit bool simply was to understand if the
OnCollisionEnter2D was working. It never went off