- Home /
Question by
Agent_Cooper · Jun 08, 2015 at 10:46 AM ·
collisionenemyhealth
Enemy health not reducing on collision with bullet
have different weapons, with one i would like to shoot real bullets, so i attached these two scripts to the bullet, but only the first works. are they interfering?
using UnityEngine; using System.Collections;
public class proj_giocatore_distruggi : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void OnCollisionEnter (Collision collision) {
GameObject prefab = Resources.Load ("esplosione") as GameObject;
GameObject esplosione = Instantiate (prefab) as GameObject;
esplosione.transform.position = transform.position;
Destroy (esplosione, 2);
Destroy (gameObject);
}
}
////This is the second script
using UnityEngine; using System.Collections;
public class danno_proj_giocatore : MonoBehaviour {
public int danno = 100;
// Use this for initialization
void Start () {
}
void OnTriggerEnter(Collider Other)
{
//Is colliding object a player? Cannot collide with enemies
if (!Other.CompareTag ("enemy"))
return;
//Get PlayerController object and update cash
Enemy_Drone EN = Other.gameObject.GetComponent<Enemy_Drone> ();
//If there is a PC attached to colliding object, then update cash
if (EN)
EN.Health += danno;
}
}
Comment
Only the second script does damage, and if you are using that on both bullets it should work fine. Unless of course your bullet is traveling at very high speeds (it might skip through the enemy before the collision is detected)