Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
-3
Question by DAX_V · Jun 16, 2021 at 09:03 PM · inventoryinventory system

how do i make an inventory system based on lists

So i have been trying to make an list based inventory system in Unity 2D (something like in enter the gungeon) for past 4 weeks and i have enough.

This is main thing that i atatch to player character (btw this code is from a answer by @niiicolai on another post )

The issues i have been having are as followes:

-can pick up things and put it into a list but i spawn all werpons and not only 1 that is equipped rn.

-have difficulties with finding gameobject with itemPickupScript (scripts find pickup once and then stops finding other pickups, which leads to me being unable to get other werpons than 1 thats get found first)

     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     
     public class InteractionMenager : MonoBehaviour
     {
         public KeyCode pickupKey = KeyCode.E;
         public KeyCode dropKey = KeyCode.G;
      
         public List<GameObject> weapons;
         public int maxWeapons = 2;
     
         public GameObject currentWeapon;
         public Transform hand;
         public Transform dropPoint;
     
     
         [Header("detection parameters")]
         public Transform detectionPoint;
         private const float detectionRadius = 0.2f;
         public LayerMask detectionlayer;
         public GameObject interactionObject;
     
         public GameObject ItemToAddPickup;
         public GameObject itemToAdd;
         
         void Update() {
     
             if(werponng.isReloading == true){
                 return;
             }
             // SELECT WEAPONS
             if (Input.GetKeyDown(KeyCode.Alpha1)) {
                 SelectWeapon(0);
             }
      
             if (Input.GetKeyDown(KeyCode.Alpha2)) {
                 SelectWeapon(1);
             }
     
             Vector2 Scalex4 = transform.localScale;
             Scalex4 *= 0.25f;
     
             ItemToAddPickup = GameObject.FindGameObjectWithTag("pickup");
     
             itemToAdd = ItemToAddPickup.GetComponent<itemPickupScript>().ItemToAdd;
     
             Vector2 werponposition = GameObject.Find("werponSlot").transform.position;
     
      
             // PICKUP WEAPONS
     
             if(DetectionObject()){
     
                 if (Input.GetKeyDown(pickupKey) && weapons.Count < maxWeapons) {
     
                     Debug.Log("working");
     
                     weapons.Add(itemToAdd);
     
                     GameObject ita = (GameObject)Instantiate(itemToAdd);
                  
                     ita.transform.parent = hand;
                     ita.transform.localScale = Scalex4;
                     ita.transform.position = werponposition;
     
                 }
             }
         }
     
     
         void SelectWeapon(int index) {
      
             // Ensure we have a weapon in the wanted 'slot'
             if(weapons.Count > index && weapons[index] != null) {                    
      
                 // Check if we already is carrying a weapon
                 if (currentWeapon != null) {
                     // hide the weapon                
                     currentWeapon.gameObject.SetActive(false);
                 }
      
                 // Add our new weapon
                 currentWeapon = weapons[index];
      
                 // Show our new weapon
                 currentWeapon.SetActive(true);            
             }
         }
     
     
     bool DetectionObject(){
     
             Collider2D obj = Physics2D.OverlapCircle(detectionPoint.position, detectionRadius, detectionlayer);
     
             if(obj==null){
     
                 interactionObject = null;
                 return false;
             }else{
                 interactionObject = obj.gameObject;
                return true;
             }
        }
     }

and i use this to get werpon from my pickup (which is another game object and i set the ItemToAdd in inspector to it)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class itemPickupScript : MonoBehaviour
 {
     public GameObject ItemToAdd;
 }
 
Comment
Add comment · Show 5
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 Captain_Pineapple · Jun 17, 2021 at 07:04 AM 1
Share

i doubt that you will get good help on this here. You are asking a lot of work from others without providing a lot of information. Especially some info on why you cannot do it on your own would be good. Why not start at why your current approach does not work? If you just say: i've had enough of my problem, now you guys can solve it for me why would anyone be keen to do so?

avatar image DAX_V Captain_Pineapple · Jun 18, 2021 at 05:39 PM 0
Share

Sorry it ws late at night when i was writing this and as i said i had enough of this. The issues i have been having are as followes:

  • can pick up things and put it into a list but i spawn all werpons and not only 1 that is equipped rn.

  • have difficulties with finding gameobject with itemPickupScript (scripts find pickup once and then stops finding other pickups, which leads to me being unable to get other werpons than 1 thats get found first)

And why am I actually here - beacose there is literary no usefull guide or code or paper on system like this (only 1 that i found was for unity 3d which i repurposed for unity 2d and my pickup system) and i'm also stuck on this for 4-5weeks which really frustrates me.

All of this was preety stupid of me but as i said it was really late at night when i was writing this p.s sorry for my bad english

avatar image logicandchaos DAX_V · Jun 19, 2021 at 07:57 PM 0
Share

you say in the post tho that the code is from someone else and now that is part of a tutorial.. maybe it is working well but implemented wrong, maybe you need to understand your code better or scale down your project until you get more advance.

Show more comments
Show more comments

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

123 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

Related Questions

Inventory Drop Function Problem 1 Answer

What is a good component to use for a GUI inventory display? 1 Answer

How to optimize this script and add items imediately without grids 0 Answers

Inventory AddItem help 1 Answer

Inventory system Stacking an item problem 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