Bullet Destroy
I have an error in my Bullet Destroy script: #pragma strict function OnCollisionEnter(coll: Collision){ Destroy(gameObject); } function OnCollisionEnter(coll: Collision){ // do whatever you want to do, then destroy bullet: Destroy(coll.gameObject); }
NOT QUESTION: (( There are multiple things wrong with my asking this question: I have started with C#, and this is in Javascript. It was one of my earlier scripts that I believe was based off of a tutorial. Also, I haven't researched an answer yet, this is my first action. The only reason I'm really asking this question now is because I'm done for the night and won't be able to get back on Unity for the majority of tomorrow, so I figured I would give this time. )) QUESTION: The error is that Unity expects a semicolon where it definitely doesn't belong, which is on line 7, where only a } is. When I add this, a bunch of errors pop up because I'm sure it doesn't belong. What's wrong with my script that makes the Unity engine believe that? Thanks
Answer by itsharshdeep · Dec 12, 2015 at 07:30 AM
Hello First of all your script contains the OnCollisionEnter Metod 2 times so firstly remove that, Second I copied your code and pasted into my script except the repeat of the method there is no any error present . Following is your code:-
#pragma strict
// function OnCollisionEnter(coll: Collision)
// {
// Destroy(gameObject);
// }
function OnCollisionEnter(coll: Collision)
{
// do whatever you want to do, then destroy bullet:
Destroy(coll.gameObject);
}
Now it might be the problem that you are not saving your script or you can do like Go in Assets>Open C# project or If you are using the older version of Unity then there is a option like sync ModoDevelop in Assets Menu
If any of the solution not worth you then you can create a c# script and then check the same If this will not work then please let us know.
Thanks
Your answer
Follow this Question
Related Questions
MY effect dont destroy 0 Answers
Destroying Bullet (Impact Effect) 1 Answer
bullet destroy on collison 1 Answer
The bullet never destroyed!!! 2 Answers
Warnings in Java 0 Answers