x


problem with shooting killing script

hey i was wondering if someone could help me i am new to scripting and think that my script should work but i have a problem that when i shoot my projectile prefab it hits the game object wich the script is atached to it gets destroyed but the game object the script is atached to dosent so its like projectile>hit game object>destroy projectile> then nothing when it should be projectile>hit game object>destroy projectile>destroy game object anyway hear is the script var Projectile = gameObject; //var Item = gameObject; function OnControllerColliderHit (hit : ControllerColliderHit) { Destroy (Projectile); Destroy (gameObject); }

more ▼

asked Jul 11 '11 at 03:46 AM

TylerPerry gravatar image

TylerPerry
1 3 3 4

Aren't you getting the following error in the console:

"ArgumentException: You are not allowed to call get_gameObject when declaring a variable."?

(CTRL + SHIFT + C to open the console if it is not)

Jul 11 '11 at 04:39 AM GuyTidhar
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

According to your script, you are trying to set the projectile with the gameObject your script is attached too and you do that at initialization time, which you may not do.

// This is not good: var Projectile = gameObject;

gameObject with a lower case g, is always the instance of the game object your script is attached too.

So you basically you are trying to tell the program to destroy the gameObject twice.

It is more likely you want something like this:

function OnControllerColliderHit (hit : ControllerColliderHit)
{ 
    Destroy (hit.gameObject); 
    Destroy (gameObject); 
}
more ▼

answered Jul 11 '11 at 04:53 AM

GuyTidhar gravatar image

GuyTidhar
2.2k 4 8 13

(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:

x5051
x3316
x764
x274
x63

asked: Jul 11 '11 at 03:46 AM

Seen: 1024 times

Last Updated: Jul 11 '11 at 04:53 AM