I’m creating a 2D space shooter, and I have my Collision function in my Bullet Script
public void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag.Equals("Enemy") || col.gameObject.tag.Equals ("Player"))
{
col.gameObject.GetComponent<Health>().TakeDamage(5);
Debug.Log("Damage Taken");
Destroy(col.gameObject);
}
}
And my Health script attached to Enemy
public class Health : MonoBehaviour
{
public int health = 100;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (health <= 0)
{
Destroy(gameObject);
}
}
public void TakeDamage(int amount)
{
health -= amount;
}
}
But my bullets go straight through Enemy and don’t detect collision, i’ve tried layers, triggers and tags but to no avail, can someone point out my flaws?