x


Destroy game object on name

var Health = 2;
var Money = 1;

function OnControllerColliderHit(hit : ControllerColliderHit)
{

var coin = GameObject.FindWithTag("coin");
if(hit.gameObject.tag == "coin")
   {
      GUI_Stats.MONEY = GUI_Stats.MONEY + Money;
        audio.Play();

    Destroy(coin);
   }
}

this is attached to may player so he can collect coin however i want to destroy the coins separately however the coins all destroy because there all tagged as coin how do i destroy the each individual coin please help thanx

more ▼

asked Jun 16 '10 at 10:08 PM

JackJones gravatar image

JackJones
62 16 18 21

@JackJones, remember to checkmark the best answer (as well as upvoting any good answers).

Jun 17 '10 at 02:13 AM Cyclops
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

Why are you destroying coin, when it's just the first game object that's found with that tag (and has nothing to do with the one you just collided with)?

You need to destroy what you just collided with instead:

Destroy(hit.gameObject);
more ▼

answered Jun 16 '10 at 10:14 PM

qJake gravatar image

qJake
11.6k 43 78 161

thanx mate it must have been right under my nose lol

Jun 16 '10 at 10:26 PM JackJones
(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:

x2083
x764

asked: Jun 16 '10 at 10:08 PM

Seen: 3817 times

Last Updated: Jun 16 '10 at 10:12 PM