- Home /
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); }
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)
Answer by GuyTidhar · Jul 11, 2011 at 04:53 AM
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);
}
Your answer
Follow this Question
Related Questions
Destroying assets is not permitted to avoid data loss.? 3 Answers
Shooting Specific GameObject via Tag 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to Destroy a gameobject on collision 3 Answers
Destroy parts of a Wall 2 Answers