• 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 JES_INC · Jan 03, 2021 at 11:53 PM · rpgrpg-gamerpg kit

Unity 3d Inventory Stacking Items [C#]

So I was doing an Inventory for my RPG game, but now I´m stuck on an Problem: I want to Stack my Items in that Inventory but I don´t know how to do this.

this is my Inventory Script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Inventory : MonoBehaviour
 {
     public GameObject Player;
     public GameObject InventoryPanel;
     public GameObject Overlay;
     public GameObject statsoverlay;
     public static Inventory instance;
     public List<Item> list = new List<Item>();
 
     void UpdatePanelSlot()
     {
         int Index = 0;
         foreach(Transform child in InventoryPanel.transform)
         {
             ItemSlotController slot = child.GetComponent<ItemSlotController>();
 
             if(Index < list.Count)
             {
                 slot.item = list[Index];
             }
             else
             {
                 slot.item = null;
             }
             slot.UpdateInfo();
             Index++;
         }
     }
 
     private void Start()
     {
         instance = this; 
         UpdatePanelSlot();
     }
 
     public void Add(Item item)
     {
         if(list.Count < 98)
         {
             list.Add(item);
         }
         UpdatePanelSlot();
     }
 
     public void Remove(Item item)
     {
         list.Remove(item);
         UpdatePanelSlot();
     }
 
 }



this is my Item Script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Item : ScriptableObject
 {
     public string ItemName;
     public Sprite Icon;
     public string description;
 
     public virtual void use()
     {
 
     }
 }
 

but the Item Script is just the base for other versions of Items just like tools or eatables and stuff. and the last Script is the Slot Controller wich controlls my Inventory Slots (like the name said):

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class ItemSlotController : MonoBehaviour
 {
     public Item item;
     public GameObject Ausklappen;
 
     private void Start()
     {
         UpdateInfo();
     }
 
     public void UpdateInfo()
     {
         Image displayimage = transform.Find("Image").GetComponent<Image>();
 
         if (item)
         {
             displayimage.sprite = item.Icon;
             displayimage.color = Color.white;
         }
         else
         {
             displayimage.sprite = null;
             displayimage.color = Color.clear;
         }
     }
 
 
     public void use()
     {
         if (item)
         {
             item.use();
         }
     }
 }
 






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

0 Replies

· Add your reply
  • Sort: 

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

114 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

Related Questions

Camera Zoom not working 1 Answer

Error CS0029 1 Answer

Rpg creator kit doesnt work? 1 Answer

UI RPG Dialog Sytem 0 Answers

Going from world to interiors of buildings in simple 3D RPG Game: teleport or new scene? 1 Answer


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