Huge Health and Damage Script Problem
This is the third time I'm asking for help with these scripts because it still doesn't work, with all the changes I've made so far. Anyway, I'm making a third person shooter. I have a bullet prefab which is shot by my enemies and my character. I'm using two scripts to do it. One is for the Bullet:
using UnityEngine;
using System.Collections;
public class MoveBullet : MonoBehaviour {
public int damage = 5;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider Enemy){
if(Enemy.gameObject.CompareTag("enemy"))
{
Enemy.gameObject.SendMessage("OnDamage", damage);
}
}
}
And the other for the Damage on the characters:
using UnityEngine;
using System.Collections;
public class Damage : MonoBehaviour {
public int damage = 5;
public int health = 100;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnDamage(){
health= health - damage;
if (health <= 0) {
Destroy(gameObject);
}
}
}
The script is largely working. When I get shot, I receive damage. When I shoot, my enemies receive damage. When health reaches 0, I die. The problem is, every time I shoot a bullet, my health drops by 5 as if I was shot. I could avoid all enemy bullets and I would still die from the damage received when I shot my own bullets. This basically makes the script unusable. Please tell me how to fix it because I'm an idiot and I have no idea (despite my best tries). Thanks!