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 Tekksin · Dec 25, 2013 at 12:10 AM · referencecustomfunctions

General function knowledge

(Just re-read the title and chuckled.)

Is there reading on setting custom functions?

I know that if you have a regular function like OnTriggerEnter (other: Collider){} you can fill it with things that are not the trigger by specifying "other." before the script. But what about custom ones?

The set up is familiar as it is normally constructed, but I've seen some function routines start off with some weird and complex stuff and I just don't get it. If it is a custom function, what goes in these blank parts?

 function Something(______ : ________){
 
 }

the rules of that have eluded me, and I'm just searching for some reading on it, but without knowing what those two blank variables are, I have no idea what to search for. Thanks for any links or info.

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 Benproductions1 · Dec 25, 2013 at 12:16 AM 0
Share

You should read up on general program$$anonymous$$g techniques. Functions take arguments and return values. What the arguments are is up to you

avatar image Tekksin · Dec 25, 2013 at 12:25 AM 0
Share

I'm aware of how simple functions work, where you don't fill in the () but I just wanna know that if I had to fill those with things, what would be appropriate and when? it's so confusing that it's hard to ask the question lol... but from your response, I'm guessing the blank spots are "(arguments : return values)" ? or did i misunderstand... ugh lol

avatar image Benproductions1 · Dec 25, 2013 at 04:37 AM 0
Share

@Tekksin What you put as arguments is completely up to you. It completely depends on the situation and what you want the function to do. (And no, that's not the syntax)

avatar image vexe · Dec 25, 2013 at 07:09 AM 2
Share

Check out my in-depth answer here. It's in C#, but the concepts are the same.

1 Reply

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

Answer by iwaldrop · Dec 25, 2013 at 12:33 AM

I'd first like to echo Benproductions' comment regarding doing some reading on programming in general.

To answer you question, however, so that it might be closed out with an answer others may also find to be useful, the parts that you're referring to are called the variable name and type name, in that order.

UnityScript:

 function DoSomethingAwesome(variableName : TypeName)
 {
     // do amazing things
 }

C#:

 void TheMostAwesomeMethod(TypeName variableName)
 {
     // hack something here
 }

In the above examples I've tried to make it as plain to see as possible. You can use the variable, 'variableName' within the scope of the function/method that defines it. This allows you to pass in values from other functions/methods. A function, by definition, returns a value that is based on another value, although in the Computer Sciency realms we accept that functions do not require variables, and do not necessarily need to return anything useful. UnityScript shields the user from the majority of that pedantry, however, while in C# you must still declare the return type even if nothing is sent back to the calling method (hence, void).

As noted below by Benproductions, another point that applies to Unity; languages typically have their own idiosyncrasies when it comes to how they define scope. Unityscript, for instance defaults the methods to being public, that is accessible outside of the defining class. C#, on the other hand defaults them to being private, or not accessible outside of the defining class. In either case, use of the access modifiers 'public' and 'private' will override the default behaviors.

Also, for more more in-depth, check out vexe's answer, here.

Now. Go find some useful books on your language of choice!

Comment
Add comment · Show 5 · 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 Benproductions1 · Dec 25, 2013 at 04:34 AM 0
Share
  • good, clear, concise

avatar image Benproductions1 · Dec 25, 2013 at 04:37 AM 3
Share

It would probably be good to mention that

 function DoSomethingAwesome() {}
 //is not the same as
 void DoSomethingAwesome() {}

UnityScript defaults to the public scope, while C# defaults to private ;)

avatar image iwaldrop · Dec 25, 2013 at 07:00 AM 1
Share

Good point. Added to answer, and +1.

avatar image Tekksin · Dec 25, 2013 at 08:35 AM 0
Share

Thanks so much! You answered everything perfect! I'm glad I made this question because now I'm going to reference it any time I have a function problem or curiosity. $$anonymous$$nowing the names of what goes in those spots separated by the colon is definitely the biggest help.

While we're at it though, I'm co$$anonymous$$g across more and more instances of people using the void functions. What are the point of those in a nutshell?

avatar image Benproductions1 · Dec 25, 2013 at 08:55 AM 0
Share

They are for functions that don't return any values. Sometimes you want to call a function that only has side effect without a return value, so void is returned ins$$anonymous$$d.

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

21 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

Related Questions

Custom On(method) Functions 3 Answers

Storing References of Custom Classes 0 Answers

Referncing variables such as OnTriggerEnter(Collider other) thumb rule? 1 Answer

Reference Function Trouble 2 Answers

How do I call a function containing a while loop, inside the update function? 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