简体   繁体   中英

Unity5 Private vs Public Gameobject

what is the difference between public and private variables , gameobjects and other things in Unity - C# ? ; Thanks for help.

The public variables can easily be changed, while the private variables cannot be easily changed.If you compile the code you can see an input for the public variable in the inspector panel, by changing the variable in the inspector panel you change the variable for that case. However, you will not see one for a private variable.

I would suggest for scripts in which will be use more than 1 times, expose the elements that would be used differently.

If a variable/function is public, other classes with access to the class can access it. If a variable/function is private, other classes can't access it. Only the class itself can use it.

Good programs try to have as few public variables/functions as possible, see Loose coupling .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM