I made a script that has to kill the enemy inside my bullet as component but it wont work it wont print health or Destroy it but i made the same script another time and i did work can someone explain why it wont work.
Script:
using UnityEngine;
using System.Collections;
public class enemyKiller : MonoBehaviour {
public int enemyHealth;
public int bulletDamage;
// Use this for initialization
void Start ()
{
enemyHealth = 100;
bulletDamage = 1;
}
// Update is called once per frame
void Update ()
{
}
void OnCollisionEnemy(Collision col)
{
if (col.gameObject.name == "enemy")
print(enemyHealth);
if (col.gameObject.name == "enemy")
enemyHealth = enemyHealth - bulletDamage;
if (enemyHealth == 0)
if (col.gameObject.name == "enemy")
Destroy(col.gameObject);
}
}