- Home /
Enemy health not reducing
i 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;
}
}
Answer by Baste · Jun 08, 2015 at 08:22 AM
The first script is reacing to collisions, while the second one is reacting to triggers.
Collisions and triggers are not the same thing, and happen in different situations - mostly this has to do with if your bullets are trigger colliders or not.
See the bottom of this page for the details.
Anyways, if you want both scripts to react to the same collision even, use OnCollisionEnter on both of them.