I have a code here (C#) so that when my bullet collides with my enemy the enemy looses life and the bullet gets destroyed, but it wouldn’t work, please help
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (curHealth <1){
Destroy(gameObject);
}
}
void OnCollisionEnter(Collision col){
if (col.gameObject.tag == "Bullet"){
curHealth -= 20;
Destroy(gameObject.tag )("Bullet");
}
}
void OnGUI() {
GUI.Box(new Rect(10,40, Screen.width / 2 / (maxHealth / curHealth), 20), curHealth + "/" + maxHealth);
}
}
I tagged my bullet as: Bullet