Quantcast
Channel: Questions in topic: "tagging"
Viewing all articles
Browse latest Browse all 120

Collider Tag not working for enemy

$
0
0
I'm having a problem with letting the bullet notice it is an Enemy. This only happens when I try to use an explosionRadius. The enemy Prefab is correctly tagged as "Enemy", but it still won't recognize it as an "Enemy". I don't know how to fix it, I've tried numerous methods, but none worked. See pictures and code to see what I mean. [code=Csharp] //Called when the bullet reaches a target void HitTarget() { GameObject effectInstance = (GameObject)Instantiate(BulletImpactEffect, transform.position, transform.rotation); Destroy(effectInstance,2f); //If this bullet has an explosionRadius > 0 then it calls the explode function (This works for the missile) if (explosionRadius > 0f) { Explode(); } else { Damage(target); } Destroy(gameObject); } //Explode function void Explode() { //Scans for each object in the radius of the explosion, if the object is tagged as "Enemy", Then it calls the damage function Collider[] colliders = Physics.OverlapSphere(transform.position,explosionRadius); foreach (Collider collider in colliders) { // Here is the problem. If I try != "Enemy" Then it removes all the objects that are not tagged as "Enemy". But when it is tagged it does nothing to the enemy? if (collider.tag == "Enemy") { Damage(collider.transform); } } } //For the moment it just destroys the gameObject void Damage(Transform enemy) { Destroy(enemy.gameObject); } [/code] ![alt text][1] [1]: /storage/temp/140178-screenshot-5.png

Viewing all articles
Browse latest Browse all 120

Latest Images

Trending Articles





Latest Images