• 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 bobola66 · May 25, 2012 at 09:31 AM · inventoryexpand

When equipping a backpack how can i make the inventory expand?

Hello. I have been working on a project that simulates a zombie apocalypse and i am trying to make it as realistic as possible but then a problem occurred. I simply have no idea how to make the inventory expand after equipping a backpack or pants with lot of pockets. Any help is previously appreciated. Thank you :)

Comment
Add comment · Show 2
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 oliver-jones · May 25, 2012 at 01:04 PM 1
Share

Your going to need to add way more information, I'm happy to help, but I cant if I don't know what I'm suppose to be helping you with? When you say 'expand inventory', are you referring to a model in the scene, that you want to physically expand the more stuff you pick up. Or are you referring to your code, if so you will need to put your code into your question.

avatar image bobola66 · May 25, 2012 at 01:14 PM 0
Share

Thank you! I haven't started to make my inventory yet so i can't provide the code. First i want to clear any obstacles that may occur so i can do it clean and not get in any mess. By expanding the inventory i mean for example i have 8 inventory slots 4 for my left pocket and the right one. But when you find a backpack and equip it the UI will change and i will get 16 slots ins$$anonymous$$d of 8.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by chaz1186 · Apr 08, 2016 at 10:09 PM

@oliver-jones I got a CS8025 error can someone help how to fix it

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

Answer by oliver-jones · May 25, 2012 at 01:32 PM

Okay, I did a rough draft of what you might be looking for, I haven't tested it, so ... expect problems:

 //this is the size of our left pocket
 var leftPocket : int = 4;
 //this is what is actually inside our left pocket
 var itemsInLeft = Array();
 
 //this is the size of our right pocket
 var rightPocket : int = 4;
 //this is what is actually inside our right pocket
 var itemsInRight = Array();
 
 var haveBackpack : boolean = false;
 
 function OnGUI(){
 
     //whatever object is added to the leftPocket/rightPocket array, it will show you in your GUI
     //show whats in the left pocket
     for(var i = 0; i < itemsInLeft.length; i++){
         GUI.Label(Rect(20, 10 + (30 * i), 100, 30), "Left: " + itemsInLeft[i].gameObject.name);
     }
     
     //show whats in the right pocket
     for(var i = 0; i < itemsInRight.length; i++){
         GUI.Label(Rect(Screen.width - 100, 10 + (30 * i), 100, 30), "Right: " + itemsInLeft[i].gameObject.name);
     }
     
 }
 
 function Update(){
     
     if(haveBackpack){
         
         leftPocket = 8;
         rightPocket = 8;
         
     }
 }
 
 //call this anywhere, with the object you want to add, and the pocket
 function AddItem(item : GameObject, pocket : String){
     
     //we are refeering to the left pocket, also check if the pocket isnt full yet
     if(pocket == "left" && itemsInLeft.length <= leftPocket){
         itemsInLeft.Add(item);
     }
     
     //again, but with the right
     if(pocket == "right" && itemsInRight.length <= rightPocket){
         itemsInRight.Add(item);
     }
 }


So whats happening is that you have an array, both for your left and right pocket. You can add an object by calling the AddItem and include the item you want to add, and which pocket. This also updates your GUI.

Let me know how it goes

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

Answer by shadowriffe · May 25, 2012 at 01:31 PM

Depending on your data structure that you use for your inventory: likely a hashmap or a list, you will want to have a block of code that executes when you put on the backpack.

Very Much Rough/Pseudo Code:

 class Backpack{
     function OnEquip{
         BroadCastMessage{"IncreaseInventory",8);
     }
 }

 class Inventory{
     function IncreaseInventory(int howMany){
         inventoryList.slots += 8;
     }
 }

You can easily set up code to do that, there are many different ways.

What might be better is to have an Inventory Manager object on your character that can hold any amount of objects that have inventory components. And when you pick up an item it just gets put in the first available slot of any inventory item by the Inventory Manager. Thus, when you bring up the inventory menu, you can iterate through each inventory, iterating through each inventory item, seperating them in the overall list by where the items are being held. You will probably want to use transform parenting for your inventories, and have checks for number of transform children to determine the inventory's current capacity. This way, when you drop the backpack item, all the items in the backpack are dropped along with it etc.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pickup/Save List not working. :( 0 Answers

Cloud recognition in Vuforia 0 Answers

Creating an interactable inventory? 1 Answer

Inventory using a TXT file... Is it possible? 2 Answers

GUI Rect not showing on play 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