Hi, Can someone tell me the difference between public, private, and static variables? When should they be used. I actually believe i understand static vars. But not the use of public and private.
Answer by Mike 3
Mar 21, 2011 at 05:13 PM
Public members are accessible from other classes
Private members are accessible only from within the class itself
Static members belong to the type/class instead of an instance - i.e. there is only one of them shared between all instances of a class
You can also use protected and internal - protected members are available from inheriting classes, internal works for other classes in the same assembly. These two probably aren't as interesting for you than the others though
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
How faster is private variables over public variables?
Explanation on how to use functions, variables from other files
Whats the difference between public and static variable?
Does Quality Level remain between scenes?
My static variable is not changing