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 /
  • Help Room /
avatar image
0
Question by 12ssmith1 · Jul 22, 2016 at 10:43 AM · c#listsinventory systemremovestorage

Removing item from list makes it appear at the bottom ?

I am trying to create an inventory box not unlike the original resident evil games, I can put items in with no issues. My problems occur when i try to remove an item. the item will be removed from the box and added to my inventory but for some reason the item will spawn at the bottom of the list. (there is a secret extra slot that the guns hiding in).

alt text

alt text

  if (inventory.ItemStorage [slotNumber].itemName == null ) 
             {
                 item = null;
                 itemAmmo = 0;
                 ItemId = 0;
                 itemIcon.enabled = false;
                 itemIcon.sprite = null;
                 ammoSet = false;
                 itemCount.count = 0;
                 itemNameText.text = "";
             }
     
         
     
     
             if (inventory.ItemStorage[slotNumber].itemName != null)
             { 
                 item = inventory.ItemStorage[slotNumber];
                 itemIcon.enabled = true;
                 itemIcon.sprite = inventory.ItemStorage[slotNumber].itemIcon;
                 itemNameText.text = item.itemName;
     
                 itemCount.count = item.itemAmmo;
                 Debug.Log (slotAmmo + " " + slotNumber);
     
     
                 if (item.itemType == Items.ItemType.Key)
                 {
                     itemCount.itemTotal.text = "";
                     ammoSet = true;
                 }
     
                 if (ammoSet == false)
                 {
                     itemAmmo = myData.ammo;
                     ammoSet = true;
                 }
     
             } 
     
             else 
                 
             {
                 itemIcon.enabled = false;
                 if (itemCount.count == 0) 
                 {
                 itemCount.itemTotal.text = "";
                 }
             }
     
         }
     
         public void OnSubmit()
         {
             inventory.ItemStorage.Remove(item);
             inventory.itemAmmo = itemCount.count;
             inventory.removeFromStorage = true;
             inventory.removeFromStorageAmmoSet = true;
             inventory.addItem (item.itemID);
     
             //inventory.removeItemFromStorage (item.itemID);
             //inventory.slotNumber = slotNumber;
     
         }
     
     }

When the slot is clicked it will run the OnSubmit function. I have tried the .Remove, .RemoveAt and making the slot null all to no avail.

 public void addItem(int id)
     {
         for (int i = 0; i < dataBase.items.Count; i++) 
         {
             
             if (dataBase.items [i].itemID == id) 
             {
                 Items item = dataBase.items [i];
                 addToEmptySlot (item);
 
                 break;
             }
         }
             
     }


 void addToEmptySlot(Items item)
 
     {
         for (int i = 0; i < Item.Count; i++) {
             if (Item [i].itemName == item.itemName && item.itemType == Items.ItemType.Ammo) {
                 stackAmmo (item);
                 stacked = true;
                 break;
             }
         }
 
             for (int i = 0; i < Item.Count; i++)
             {
             if (Item [i].itemName == null && removeFromStorage == false && stacked == false) 
             {
                 Item [i] = item;
                 //Item [i].itemAmmo = itemAmmo;
 
                 Item.Add (item);
                 break;
             }
             else if (Item [i].itemName == null && removeFromStorage == true && stacked == false) 
             {
                 //ItemStorage.Remove (item);
                 Item [i] = item;
                 defaultInt = Item [i].itemAmmo;
                 Item [i].itemAmmo = itemAmmo;
                 Debug.Log (Item [i].itemAmmo);
                 Item.Add (item);
                 //ItemStorage.Remove (item);
                 //Item [i].itemAmmo = defaultInt;
 
                 removeFromStorage = false;
 
                 break;
             }
 
             }
         stacked = false;
         }

I have spent a day and as many fixes as I could conjure, sorry if the post doesn't adhere to standards, this is my first one.

So bluntly, when i click the storage slot the item should enter my inventory and be completely removed from storage.

If you need more info, simply ask and thanks in advance :).

p1.png (440.2 kB)
p2.png (461.3 kB)
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
Best Answer

Answer by 12ssmith1 · Jul 24, 2016 at 09:07 PM

It's okay, all i needed was a break. Turns out i was adding it twice. Anywho problem solved.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How Can Storage Be Done If Unity Deletes Or Duplicates Gameobjects? 0 Answers

How do I pull variables from an object in a list? 1 Answer

Save gameobjects in a list before destoying 0 Answers

Using foreach to remove and delete bullet in List - C# 3 Answers

All crops in list growing at once when they are supposed to grow individually 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