x


OverlapSphere Limit colliders

Hi. Here's my code:

var colliders : Collider[] = Physics.OverlapSphere (transform.position, 3);
   for (var hit in colliders) {
   if (hit.transform.parent.tag == "EnemyShip" || hit.transform.parent.tag == "EnemyGround") {
   hit.transform.parent.GetComponent("enemyShipScript").takeDamage(bulletDamage);
   print("Hit!");
   }
} 

My problem is that it prints "Hit!" for every collider that the enemy has. My enemies have several colliders. How do I limit it so that it only applies the damage once per enemy?

more ▼

asked Aug 17 '10 at 12:32 PM

Icemourne gravatar image

Icemourne
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

What I'm doing is to search for a specified component In my case it's "DamageReceiverComponent" in a hierarchy. Starting from a collider.gameObject moving up (I do not search in children). Now I have got a list of DamageReceiverComponents, I remove all duplications and apply damage to unique ones. DamageReceiverComponent.ReceiveDamage(IDamage damage);

more ▼

answered Jan 31 at 05:54 PM

koirat gravatar image

koirat
76 1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1684
x651
x60
x36

asked: Aug 17 '10 at 12:32 PM

Seen: 1190 times

Last Updated: Jan 31 at 05:54 PM