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 frogsbo · Jun 07, 2014 at 11:10 PM · functionparameters

U3D version 4 optional function parameters in javascript and c#

Can someone please demonstrate the Unity3d optional function parameters? i.e.

 function human(name:string,required;    age: int, optional;   shoesize:float,optional;  haircolor : Color : optional)

...

is there a way of invoking the above function with different combinations, just say the human'name and hair color, the human's name and shoe size?, the compiler could recognise which parameters were intended according to their data type?

Comment
Add comment · Show 4
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 MrFijiWiji · Jun 07, 2014 at 11:18 PM 0
Share

Just to let you know, 4 questions down from this one is another question almost identical. Doing a quick search would have brought up quite a few. Here is a link to the question 4 down from this one:

Optional Parameters

avatar image frogsbo · Jun 07, 2014 at 11:28 PM 0
Share

that question is from 2009, because it has 50 lines with no current answers in them, i thought i would write a new question. if you have 10x 10 line functions with 3 parameters, the solution on that page would take 300 lines of code, compared to 30 lines in unity4... it's easier to edit.

avatar image MrFijiWiji · Jun 07, 2014 at 11:48 PM 0
Share

Sorry about that, i didn't really check the dates. It was only 4 questions down so i assumed it was quite recent. In any case, i believe what you're asking is quite simple. The following should provide you with an optional Vector3 parameter:

 public void Blah(Vector3 optionalV3 = default(Vector3))
 {
 //this will default the Vector3 to 0,0,0 when not provided.
 }

I'd imagine the same can be accomplished with other types, such as a string:

 public void Blah(string optionalS = default(string))
 {
     //this will create an optional string parameter.
 }

So in conclusion, as long as a parameter has a default value, it should become optional, whereas leaving a parameter value free would make it a requirement.

For the sake of completion, here is the $$anonymous$$SDN page with information on the subject:

Named and Optional Arguments (C# Program$$anonymous$$g Guide)

avatar image frogsbo · Jun 08, 2014 at 03:34 PM 0
Share

Oh ok, that makes alot of sense, i clearly drank too much at lunch and didnt search for the solution properly, there's a brilliant page here with lots of solutions for JS http://answers.unity3d.com/questions/56502/creating-function-with-default-arguments.html

1 Reply

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

Answer by frogsbo · Jun 08, 2014 at 03:34 PM

see http://answers.unity3d.com/questions/56502/creating-function-with-default-arguments.html for solutions

Comment
Add comment · 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

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Attach a function to different buttons and pass different parameters 1 Answer

boolean as function parameter/argument 2 Answers

Change functions parameter with UI- slider? 0 Answers

How can I storing the IEnumerator with parameters? 1 Answer

Function is being called even when not told to 2 Answers


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