I am currently working on a FPS game for a school assignment. The main question that i have is what is the most effective way of changing health loss/damage of gun based on weapon displayed using prefab shooting ?
i have already tried using a switch statement and also checking whether the object is active in the hierachy (ie. weapon01.activeInHierarchy).
My Code is Below
using UnityEngine;
using System.Collections;
public class bullet : MonoBehaviour {
public EnemyHealth eh;
// Use this for initialization
void Start () {
Destroy (this.gameObject, 1);
}
void Update(){
}
//function works for zombie bullet collision
void OnTriggerEnter (Collider other) {
if (other.tag == "Enemy") {
Debug.Log ("Enemy Hit");
eh = (EnemyHealth)other.GetComponent (typeof(EnemyHealth));
eh.ChangeHealth (-20);
} else {
Debug.Log ("Didn't hit the Enemy");
}
}
}