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 Jeff Ciaccio · Jun 10, 2010 at 12:37 PM · functionclass

what is the difference between a function and a "class function"

what is the difference between a function and a "class function"?

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

4 Replies

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

Answer by fherbst · Jun 10, 2010 at 03:01 PM

Another meaning of "class function" could be static functions inside a class:

public class Tree : MonoBehaviour { private static int numberOfTreesCreated = 0;

public static int getNumberOfTreesCreated() { // If it wasn't just the treecount, you could do some calculations here return numberOfTreesCreated; }

void Start() { numberOfTreesCreated++; } }

You could then have a gameObject with the Tree script attached and would have access to

Tree.getNumberOfTreesCreated()

(with capital T, because its a static class method) from anywhere, which returns the total number of trees created. Maybe you meaned this?

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
avatar image
0
Best Answer

Answer by Jeff Ciaccio · Jun 10, 2010 at 03:30 PM

While looking at the documention, I noticed two sections: functions and class functions.

So to use a "function", I need to instantiate and object and then allow that instance to call the function.

If it's a class function, it's a static function that can be called outside by simply using ClassName.classFunction. If there are variables updated in here, they must all be static too so there is only one copy, right?

Is this accurate?

Comment
Add comment · Show 1 · 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 fherbst · Jun 10, 2010 at 04:23 PM 0
Share

Yes, this is accurate. $$anonymous$$y source code example above does exactly this. Inside Unity there are some class functions like GameObject.Find, which searches through all game objects in the scene. On the opposite, non-static functions are accessed through the instance of the object - for example gameObject.Find, which searches inside this particular GameObject and its childs.

avatar image
4

Answer by newbrand · Jun 10, 2010 at 01:00 PM

Hm...

  • A "class function" (better: method or member function) belongs to a class, a function doesn't.
  • Methods are things a class can do while member variables are things it is. A dog for instance can Bark() (method) and has a variable itsAge (member variable).
  • You can not call the method of a class, you must call the method of a class instance (object): Not Dog.Bark(), but var sparky: Dog = new Dog(); sparky.Bark(). See a class as a blueprint and an instance of it as the real thing.

In Unity, all functions are methods as all scripts are also classes/objects, so there's no difference at all.

Actually you can, if you declare the method as static, but that's maybe a bit too much for now...

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
avatar image
0

Answer by dhendrix · Jun 10, 2010 at 12:57 PM

If your question is asking what I think you are asking then a class function can only be called through instances of that class. Your question is kind of vague though.

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

No one has followed this question yet.

Related Questions

Unity C# Start function without extending Mono 2 Answers

InvokeRepeating couldn't be called for a function inside an instanced object 1 Answer

Return a custom class from function 1 Answer

using functions as classes 1 Answer

c# passing classes through functions 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