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 navigate the site 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.
Explanation on how to use functions, variables from other files
How faster is private variables over public variables?
what public variables can be shown and changed in the inspector
call variable from string?
AddComponent with exposed