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 Drshk7 · Sep 10, 2013 at 12:11 AM · c#stringclassprivate

CSharp Classes = Scripts? Difference between private string and normal string?

I just started learning CSharp / C# but I wanted to know if classes are basically scripts. Also, if they are, why do people make ten different scripts when they can use one script with ten classes? Also, what is the difference between private string and normal string (ex: string asdf;)? What is a vector? And vector3? What do use new for?

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

1 Reply

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

Answer by darthbator · Sep 10, 2013 at 12:30 AM

You can jam 12 classes into 1 file if you would like but that's super messy, hard to work with, and likely won't function if you are deriving from MonoGame in order to have you scripts participate in the component system inside unity.

When I first started this helped me a lot. A class is a "folder" and contains methods which are basically "files". A class holds a number of methods that are logically grouped together (and often depend on one another).

People encapsulate into 1 script -> 1 file because it makes sense.

The exposure level of a parameter defines what can access it. A public parameter can be accessed from classes that inherit from the base class (the one the public var is declared in), or from other objects accessing the parameter through the component system.

Comment
Add comment · Show 4 · 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 AndyMartin458 · Sep 10, 2013 at 12:16 AM 1
Share

Hey, it's a long journey. I suggest a nice book on C#.

  1. scripts are .cs files when you think of C#

  2. a file can only contain one mono behavior which must have the same name as the class. This is why you need multiple files for multiple classes. It also makes it easier to know where your classes are. You might need a player object to have 2 mono behaviors, so you would place the two different .cs files on the player prefab in the inspector.

  3. private strings can only be accessed inside the scope of that class. Conversely, if you have reference to a class with a public string, you can access all the public strings. You won't be able to see the private strings from that other class.

Also, in Unity, public strings show up on the object in the Unity inspector whereas private strings do not

avatar image Hoeloe AndyMartin458 · Sep 10, 2013 at 08:21 AM 0
Share

I should add that it is generally good practice to keep as many variables private as possible. This prevents them from being accidentally modified in future, and helps keep your project clean.

avatar image Drshk7 AndyMartin458 · Sep 17, 2013 at 02:06 AM 0
Share

This answer was helpful, but the other one was more understandable. Sorry! :P But I thumbed you up. :D

avatar image AndyMartin458 AndyMartin458 · Sep 17, 2013 at 04:39 PM 0
Share

Thanks for runner up. :)

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Generate Json from Class Type List 1 Answer

C# Error help ( error CS0023 The `!’ operator cannot be applied to operand of type `string’ ) ??? 1 Answer

When issuing to print a private variable from the script, the script prints all the variables attached to objects using the same script instead of the specific object. How do I fix this? 3 Answers

string.TrimEnd() is ignoring a character. 1 Answer

Field is never assigned to and will always have its default value. 0 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