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 · Jun 26, 2018 at 06:01 AM · inventoryinventory systembegginerpickups

Items Changing Player Stats, Backpack increasing Inventory Size

I was just curious how this can be done. In a game like PUBG for example, when you pick up a backpack, the amount of items that one can carry will increase. I am having a bit of trouble wrapping my head around how to implement this concept.

Would you have a function that gets run whenever a specific backpack is picked up, or would you just have the backpack item edit the inventory system itself?

This item would need to act similarly to a power up no?

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
2
Best Answer

Answer by Sonky108 · Jun 26, 2018 at 07:45 AM

I guess it can be done in many ways. For example you can start with having base backpack class:

 public abstract class Backpack
 {
     private int maximumWeight;
     private List<Item> items;
     
     public Backpack(List<Item> items = null)
     {
         this.items = new List<Item>(); 
         this.items = items;
     }
 }

The you can add three class (one per tier):

 public class SmallBackpack : Backpack
 {
     maximumWieght = 10;
 }
 
 public class NormalBackpack : Backpack
 {
     maximumWeight = 15;
 }
 
 public class BigBackpack : Backpack
 {
     maximumWeight = 20;
 }

Some class containing information about player should have field and a method:

 private Backpack playerBackpack;

 public void ChangeBackpack(BackpackType newBackpackType)
 {
     switch(newBackpackType)
     {
         case(small):
             playerBackpack = new SmallBackpack(playerBackpack.items); //it will move current items to new backpack
             break;
         case(normal):
             playerBackpack = new NormalBackpack(playerBackpack.items);
             break;
         case(big):
             playerBackpack = new BigBackpack(playerBackpack.items);
             break;
     }
 }

After all another class, for example WorldItem can call Player.ChangeBackpack(BackpackType).

I've missed some null checks, correctness and in my opinion WorldItem calling method on player is basically bad idea, but I hope you get the point :)

Comment
Add comment · Show 2 · 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 · Jun 26, 2018 at 04:22 PM 0
Share

I would give you more points for this QUALITY of answer, but I only have 6.

avatar image Sonky108 DaUr3 · Jun 26, 2018 at 05:18 PM 0
Share

Thanks a lot!

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

89 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 avatar image

Related Questions

Adventure Game tutorial, Replacing models in the game world? 0 Answers

How to split the objects in the inventory 0 Answers

Deleting item from inventory system... 1 Answer

How can I delete an item from this inventory system? 1 Answer

Inventory system help - getMouseButtomDown problem 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