• 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
Question by masteproofgamel · Jul 03, 2016 at 06:58 PM · c#uiscript.ui imageinventory system

Question about an inventory system idea

So I have a basic.idea of how I can do an inventory but I dont know a thing really important. When I enter in the object's collider it is destroyed and added in the inventory by just saying inventory.Add but I dont know how in the inventory I can add this item graphically to the first slot. I know.I can set.the item icon would be the same as the item's but how can I set the first slot? And if the first.slot isn't empty the second?

Comment

People who like this

0 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 bodec · Jul 03, 2016 at 07:41 PM 0
Share

run a check on your array you are using. if slot one is not == null assign it there else check next slot until it finds one that is equal to null. then have a function that takes a int as that will be the location the item is in the array and use it to assign a graphic in the bag with

avatar image masteproofgamel · Jul 03, 2016 at 08:28 PM 0
Share

So I have a list of items that are 30 slots in the inventory. When I pick up an item I add.it to the inventory and give it and ID likee 1 and in the slot script i say: if(itemThere == null) itemThere.= 1. slotEmpy = false; Could be this a goodway? And in the second slot i say if slot 1.slotEmpty = false itemThere = 2. Is it.understable?

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Fire_Cube · Jul 03, 2016 at 07:37 PM

you loop in every slot possible, and check if they are empty. If they are, you place the item there and stop the loop. If none are, just drop the item. Just do a mono behaviour on every slot that contain the item and make it render.

Comment

People who like this

0 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 masteproofgamel · Jul 03, 2016 at 08:20 PM 0
Share

Can you please give me an example in c#? I still dont understand.

avatar image

Answer by pipe01 · Jul 05, 2016 at 08:49 PM

This is an example to what Fire_Cube said:

 bool AddItem(int item)
 {
     foreach (var slot in inventory.slots)
     {
         if (slot != -1)
         {
             slot = item;
             return true;
         }
     }
     return false;
 }

This function will return true if the item was successfully asigned to a slot, or false if there isn't enough space, in which case you may drop the item or whatever.

Also, this is assuming that your items are stored as integers, and that an empty slot is represented as -1.

Comment

People who like this

0 Show 0 · 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

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

Switch between set of images after pressing key 1 Answer

Click ui text to dissapear in 3D unity 2017 first person game script for ui multiple texts?,Clicking Text away in Unity 2017 3D first person game 0 Answers

2D Image not appearing in game but only in scene 1 Answer

How to change the color of a UI cross hair using Raycasts 1 Answer

Problem with inventory asset' script and its working 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