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 /
This question was closed Jul 28, 2013 at 11:21 PM by code-blep for the following reason:

Other

avatar image
0
Question by code-blep · Jul 28, 2013 at 12:43 AM · classenum

Enums and Class - A general question

Hi,

Am I right in thinking that when I create and Enum or a Class that it is automatically visible throughout the project. If I understand this right, could I use these to create and update my data structure more easily. I think I have been doing things the hard way face palm

If the above is correct, is there anything else that behaves in this manner? And are there any pitfalls I should watch out for using these methods?

Thanks

Paul

Comment
Add comment · Show 4
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 Jamora · Jul 28, 2013 at 01:19 AM 1
Share

If you create your enums or classes public in the global namespace they will be visible in the project. But I'm confused, because every script file you've written in Unity has been a class... If you want help in maintainable data structures, I'll gladly throw in my 2 cents. First I'll need to know what it's for and preferably what you have now.

I'm not sure what behavior you're referring to, static classes?

avatar image code-blep · Jul 28, 2013 at 11:42 AM 0
Share

Hi Jamora,

Unity is the first time that I have actually really started to learn coding, and so I have been learning bit by bit in my spare time, but it looks like I might have to learn the basics about coding in general. As your statement everything I have written is technically a class which raised my eyebrows lol!

So I have started exploring classes to hold information about weapons. For example (I'm using UnityScript):

 class WeaponsClass {
     var weaponName = "";
     var weaponIs$$anonymous$$issile : boolean;
     var weaponIsLaser : boolean;
     var weaponIsProjectile : boolean;
     var weaponPowerUsage : float;
 //And so on...
 }

I'm also exploring enums to select what weapon to use. I've used them before but not much. So last night I noticed that I could not use the same name for a class or an enum as I was about to re-create them in another script. That's when I realised that they seem to be public in the entire project. It was then I realised I could be a lot more efficient in the way I structure everything.

So that's the background to it all. I'm really excited that I could be more efficient about sharing data in the project without using static variables and so on. So it got me wondering if anything else like class, and what I should be careful about.

If also noticed untiy have updated the tutorials since the last time I looked and found this one: http://unity3d.com/learn/tutorials/modules/beginner/scripting/classes

I'll be looking through more of them today.

avatar image Jamora · Jul 28, 2013 at 04:23 PM 0
Share

I think you the Unity lessons will answer most of your questions.

You asked for other things like classes, so I would like to point out that there is also a data type similar to a class called a struct. It is a value type ins$$anonymous$$d of a refrence type.

As for the pitfalls you asked, classes are stored by refrence, so you might have two different fields point to the same instance of a class, in which case any change made to one of them will be reflected in the other. Structs, being value types, don't exhibit this behavior.

avatar image code-blep · Jul 28, 2013 at 11:20 PM 0
Share

Yeah, spent a while on them today and now re-writing a bunch of stuff. Feels good! Thanks Jamora.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Enum style variable 2 Answers

Finding the length of an enum in a different class 1 Answer

Unknown identifier: 'types'. js(38,61) 1 Answer

Logic and datatype existential problem 2 Answers

Viewing Class variables in inspector? 1 Answer


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