Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DaUr3 · Jul 02, 2018 at 06:59 AM · inventoryitemitemsitem pickup

Best Way to do Regular Items and Weapons/Intractable/Special Items.

I was just wondering if there was a good way to differentiate between a regular item and a special item in game.

To give a little more detail to what I am talking about, say you are playing a like Fortnite or PUBG. In Fortnite whenever you pickup an item such as Ammo or Building Materials, they are added to separate inventories, and in PUBG guns get their own special inventories.

Right now to determine if Items are have a special property, I just cast the pickup item as a Weapon (as Weapon extends off of Item)

 public void PickupItem(Item item) {
 if (item.type == ItemType.WEAPON) {
 Weapon weapon = (Weapon) item;
 // Do thing
 
 }
 }

I feel like this isn't the best way to do things, but that's kind of all I have right now. I am also using the type of enumeration to determine what type of interface said item is interfacing.

Basically, This question is kind of general. I am asking about the following points:

  • Is there a better way to implement item pickup besides checking an enum and then casting to another more specific type?

  • Should the base item class have methods that listen to input? I thought this would kind of be weird because you don't need an attack1() or attack2() method in an item like wood, but you would need them if you are making an Assault Rifle.

  • Currently my base Item class extends Monobehaviour so I can easily attach it onto objects, but I feel like because of this system, the Item Inventory might be a bit less inefficient. Should I split the current Item base class into a sort of Item Monobehaviour and another Item ScriptableObject/Class?

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
0

Answer by Shameness · Jul 02, 2018 at 07:22 AM

This is not long exact answer but you should really see this: https://unity3d.com/learn/tutorials/topics/scripting/inheritance .

Or this is better if can get grasp of it: https://unity3d.com/learn/tutorials/topics/scripting/interfaces .

Basically, you treat gun and material like they are same object. You pick them up, select them from their inventory, use them. But they are different. You save them to different inventory, etc.

Tell me if this helps to your issue.

Comment
Add comment · Show 1 · 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 DaUr3 · Jul 03, 2018 at 04:56 AM 0
Share

That helps, but I am still wondering if my material item should have an attack()/reload() method?

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

88 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 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 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 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 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

Decorator pattern for inventory item class 0 Answers

Using enums to design an inventory system? 1 Answer

[SOLVED] Inventory Stacking Problem [C#] 2 Answers

How to add item to my inventory when I pick them up? 1 Answer

*What are some ways of implementing a Mid Mission Weapons/Upgrade/Equipment store? 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