Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 davidwalmsley · May 25, 2013 at 06:05 AM · enumpopupstatic class

Best way to access static variables from the inspector

Ill start by by saying Im not sure if this is the best way to go about doing this, but its the best way I could come up with. So any suggestions on doing it a different way are welcome.

So, for my inventory, I have a class called Item with a bunch of variables (name and stock are the main two applicable here). To store them, I have created a static class name Inventory. In the constructor of Inventory I have created every item, with a stock starting out at zero. To add an item, I have a function that checks if the stock is less than one, if so I add it a generic list (Items.List) and add +1 to the stock. If the item's stock is greater than zero, I just add one to the stock. Inventory.Items becomes my active inventory, which is working like I want it to.

The problem I am running into is in my chests. I want them to give you some item from the Inventory class, and if the chest is locked it checks to see if an item (Inventory.key) has a stock of greater than zero. This is also working well also. What I want to do is make an option in the chest script that has a drop down menu where you can select the item to give, and select the item that unlocks it, so that I can change those two easily from the inspector from the same chest script.

I thought that creating an enum within the Inventory class might be a good way to go, but I don't how make the enum assign an item variable from the Inventory class to the chest class.

I would do a switch, but I have feeling inventory being static would give all kinds of problems with different chests that need different items assigned to them.

I just really want a field in my chest class where I choose from items that access them in the Inventory class. I thought about using a string var, but I don't know how to (or if I can) convert that string to a variable. For example, an item in the Inventory class is potion. to access it as an item variable i just script Inventory.potion. Is there a way to get stay an item variable that is Inventory."String", like make the string "Inventory.potion" and convert the string into the variable?

I also though about making separate scripts that I fed into the chest script, but I dont like having so many scripts attached to an object, and that would turn into alot of tiny scripts with all the chests and whatnot.

Any help or suggestions would be appreciated, thanks.

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

0 Replies

· Add your reply
  • Sort: 

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

14 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

Related Questions

SerializedProperty for Enum with EnumPopup 6 Answers

fftWindow isn't enum C#? 1 Answer

Very strange behavior after compiling for PC 0 Answers

CustomEditor EnumPopup using Images instead of enum values 0 Answers

KeyCode in custom editor 2 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