• 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 yoger · Feb 19, 2013 at 12:40 PM · classitemsequipment

Checking Item class

I arranged full equipment so you can put on the chest armor, helmet and other things. All items are stored as Items (thats main class), and there are also classes which inherit from Items (Weapon, Armor, Jewelry). Now in Weapon, Armor and Jewelry class i defined enums with types of following items, so for example theres Dagger, Sword and Axe in Weapons, Helmet, Chest and Gloves in Armors. Now when I equip weapon I'd like to check if the Item() (because inventory is storing everything as Item()) is actually a Weapon() or Armor(). And how after that I can access variables from those classes?

I had another enum in Item class, so I could do that without troubles, but I don't think its correct way to do it. If there's another way, please let me know.

Comment
Add comment · Show 3
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 yoger · Feb 19, 2013 at 02:09 PM 0
Share

Never mind. I found that I can access those variables by typing ((Weapon)inventory[cnt])((Armor)inventory[cnt]) etc. Thanks anyways :]

avatar image Professor Snake · Feb 19, 2013 at 02:14 PM 0
Share

You should convert that comment into an answer and accept it.

avatar image yoger · Feb 19, 2013 at 02:16 PM 0
Share

I do that. Thank you.

1 Reply

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

Answer by yoger · Feb 19, 2013 at 03:44 PM

Never mind. I found that I can access those variables by typing ((Weapon)inventory[cnt])((Armor)inventory[cnt]) etc. Thanks anyways :]

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 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

Related Questions

Inventory, Items and Equipment: is there a good way to make them? 3 Answers

'Item' class with various effects 2 Answers

c# Unexpected symbol '=' in struct, class..... 1 Answer

I need to find inventory and item system, and to save them 0 Answers

Inventory armor wielding proplem,How to convert from derived to base 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges