- Home /
Question by
Hanley_1243 · May 12, 2014 at 04:44 PM ·
javascript
why is my projectile with a destroy enemy script destroy everything it hits?
here is my script (its a javascript by the way) :
var Explosion : GameObject;
var Enemy : GameObject;
function OnCollisionEnter(hit : Collision)
{
if(hit == "Enemy");
{
Destroy(gameObject);
Destroy(hit.gameObject);
var effect : GameObject;
effect = Instantiate(Explosion, transform.position, transform.rotation);
}
}
Comment
Answer by robertbu · May 12, 2014 at 05:14 PM
You have two problems here. The thing that is causing your code to destroy everything is the ';' at the end line 10. In addition, the evaluation inside the 'if' is wrong. You are comparing a string to a collision. You want either:
if (hit.collider.name == "Enemy")
or
if (hit.collider.tag == "Enemy")
Note no ';' at the end of the line.
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Flipping textures 0 Answers
How do I invert the Y axis in Penelope tutorial? 3 Answers
Rotating a Sphere with the mouse? 1 Answer