- Home /
Error in script
var explosive : Transform; var explosion : Renderer; //Particle Prefab goes here.
function PlaceExplosive (position : Vector3, rotation : Quaternion = Quaternion.Identity, time : float) { var detonator : Transform = Instantiate(explosive, position, rotation) as Transform;
yield WaitForSeconds(time);
Destroy(detonator.gameObject);
Instantiate(explosion, position, rotation);
}
Thats the script, i have about 5 errors in the function so please help me!
Please add code formatting tags when posting your scripts, and seeing your exact errors is likely to help.
$$anonymous$$y tired eyes can't spot any glaring errors. Where's PlaceExplosive called from? Also, as above - if you can post the exact errors, it's likely to make assisting easier.
I'm not 100% sure because i don't use JS in Unity, but i guess if you define default values for parameters they have to be at the end of the parameter list. Remove the default value "= Quaternion.Identity" or make it the last parameter. You get about 5 errors... Unity tells you the exact position in your code (linenumber and column). Double click on the error to jump the position in your code.
Answer by Jessy · Feb 15, 2011 at 12:54 PM
There's only one problem in your script, which leads to other problems. You can't set up default parameters, as has been done by UT in C++. So take out your = Quaternion.Identity and all will be fine, except for having to pass the parameter, of course. One important thing to note is that the way you have it set up, your default parameter wouldn't be serving a purpose, in the hypothetical situation where you could use it. The time variables comes last, and it doesn't have a default value, so you'd have to pass a value for rotation. (You could put rotation last, and that would work - again, hypotehtically.)
You could overload the function, having another one that doesn't use that parameter, and then calls the one you already wrote:
function PlaceExplosive (position : Vector3, time : float) {
PlaceExplosive(position, Quaternion.identity, time);
}
Also, it's Quaternion.identity, not Identity. It doesn't matter though, because it needs to go.
Off topic :) I will give you a vote up so you reach 8000. :)
On the other hand, it should be Quaternion.Identity - properties in .NET should generally be capitalized. Seems like they went lowercase to make it look like they're variables shrugs
Your answer
Follow this Question
Related Questions
Windows Script error upon opening a new javascript behavior script. 4 Answers
enemy mechanics script and declining health 1 Answer
syntax errors 1 Answer
I need help with the eval() function of javascrit 1 Answer
Problems with java script. 1 Answer