Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by joeybubble1 · Feb 15, 2011 at 12:25 PM · javascripterror

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!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image · Feb 15, 2011 at 12:37 PM 1
Share

Please add code formatting tags when posting your scripts, and seeing your exact errors is likely to help.

avatar image · Feb 15, 2011 at 12:47 PM 1
Share

$$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.

avatar image Bunny83 · Feb 15, 2011 at 12:48 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FLASHDENMARK · Feb 15, 2011 at 01:11 PM 0
Share

Off topic :) I will give you a vote up so you reach 8000. :)

avatar image Mike 3 · Feb 15, 2011 at 01:44 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges