Refactoring

Hello in this course

  1. I find I can use SerializeField without assign Unity UI, unlike previous course what is different?
  2. usually i use public void when i make a method, in this time we no need to do that? what is different too?

Hi,

Thank you for your questions. :slight_smile:

  1. Is the variable public? If so, Unity exposes the variable in the Inspector.
  2. We use the public access modifier only if another object needs to call our method. If we need our method only within the same object, we prefer the private access modifier. That makes our code more secure because other objects will not be able to access everything in our object.

Did this clear it up for you?


See also:

1 Like
  1. can you explain me about function of [SerializeField ] if possible, can share me me the doc too?
  2. can you show me some example which i can try to understand more? or maybe case study.

Here are some docs related to your questions, this is a little technical.


i still not get it, can you share some example so i can understand more?
or maybe some case study?

  1. yes it is public, what if i didn’t use public? it won’t show in inspector?
  2. if we use private, if i accidentally use the same namespace for the method my code still has no problem. if i use public i might find some issue?

Ben and Rick adress this topic in their hangout video in the Block Breaker section as of the 9:23 mark. The video is named “Block Breaker Instructor Hangout #2” (currently #84 on Udemy).

  1. yes it is public, what if i didn’t use public? it won’t show in inspector?

Without the [SerializeField] attribute, the variable would not appear in the Inspector.

  1. if we use private, if i accidentally use the same namespace for the method my code still has no problem. if i use public i might find some issue?

Could you please share an code example? I’m not sure if I understood your idea correctly.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms