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 /
avatar image
0
Question by $$anonymous$$ · Oct 23, 2017 at 09:43 AM · uiui imageinventory systemmousewheelslot

Problem when scrolling through inventory slots

Hi, I'm almost finished making my inventory system, and I am using the mouse wheel as a method for the player to scroll through their inventory.slots. The problem here is that the GUI that hovers over the in-game selected slots is out of sync with the actual selected slot, it will always be one slot ahead for some reason. The other problem is that when the scrolling forwards through the slots, if scrolled backwards once, it will still go forwards another slot, and if scrolled backwards again, it will go back a slot, and the same for vise versa. I have no clue why it is doing this, but it is a strange issue and is really bumming me out. :(

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class InventoryScript : MonoBehaviour {
 
     public PropertiesScript VarPropertiesScript;
     public StatsManagerScript VarStatsManagerScript;
     public GameObject InventoryUI;
     public GameObject PutInInv;
     public GameObject Player;
 
     public GameObject InventorySlot1;
     public GameObject InventorySlot2;
     public GameObject InventorySlot3;
     public GameObject InventorySlot4;
     public GameObject InventorySlot5;
     public GameObject InventorySlot6;
     public GameObject InventorySlot7;
     public GameObject InventorySlot8;
     public GameObject InventorySlot9;
 
     private GameObject InventorySlotItem1;
     private GameObject InventorySlotItem2;
     private GameObject InventorySlotItem3;
     private GameObject InventorySlotItem4;
     private GameObject InventorySlotItem5;
     private GameObject InventorySlotItem6;
     private GameObject InventorySlotItem7;
     private GameObject InventorySlotItem8;
     private GameObject InventorySlotItem9;
     public string ButtonToOpenInventory;
     static public GameObject LookingAt;
     public GameObject GUISlots;
     public GameObject SelectedSlot;
     public string ButtonToPickup;
     public Text InventorySlotItemText1;
     public Text InventorySlotItemText2;
     public Text InventorySlotItemText3;
     public Text InventorySlotItemText4;
     public Text InventorySlotItemText5;
     public Text InventorySlotItemText6;
     public Text InventorySlotItemText7;
     public Text InventorySlotItemText8;
     public Text InventorySlotItemText9;
     public string NullText;
     private int SelectedSlotNumber = 1;
     private int SelectDisappearTimer;
 
     void Start () {
 
     }
     
 
     void Update () {
 
         if (SelectedSlotNumber > 9) {
             SelectedSlotNumber = 1;
         }
 
         if (SelectedSlotNumber < 1) {
             SelectedSlotNumber = 9;
 
         }
 
         SelectDisappearTimer += 1;
         SelectedSlot = GameObject.Find ("Slot" + SelectedSlotNumber);
 
         if (InventorySlotItem1 == null && PutInInv != null) {
             InventorySlotItem1 = PutInInv;
             InventorySlotItemText1.text = InventorySlotItem1.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
         if (InventorySlotItem2 == null && PutInInv != null) {
             InventorySlotItem2 = PutInInv;
             InventorySlotItemText2.text = InventorySlotItem2.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
         if (InventorySlotItem3 == null && PutInInv != null) {
             InventorySlotItem3 = PutInInv;
             InventorySlotItemText3.text = InventorySlotItem3.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
         if (InventorySlotItem4 == null && PutInInv != null) {
             InventorySlotItem4 = PutInInv;
             InventorySlotItemText4.text = InventorySlotItem4.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
         if (InventorySlotItem5 == null && PutInInv != null) {
             InventorySlotItem5 = PutInInv;
             InventorySlotItemText5.text = InventorySlotItem5.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
         if (InventorySlotItem6 == null && PutInInv != null) {
             InventorySlotItem6 = PutInInv;
             InventorySlotItemText6.text = InventorySlotItem6.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
         if (InventorySlotItem7 == null && PutInInv != null) {
             InventorySlotItem7 = PutInInv;
             InventorySlotItemText7.text = InventorySlotItem7.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
         if (InventorySlotItem8 == null && PutInInv != null) {
             InventorySlotItem8 = PutInInv;
             InventorySlotItemText8.text = InventorySlotItem8.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
         if (InventorySlotItem9 == null && PutInInv != null) {
             InventorySlotItem9 = PutInInv;
             InventorySlotItemText9.text = InventorySlotItem9.name;
             PutInInv.gameObject.SetActive(false);
             PutInInv = null;
         }
 
 
         if (Input.GetAxis("Mouse ScrollWheel") > 0) {
             SelectDisappearTimer = 0;
             SelectedSlotNumber += 1;
             GUISlots.SetActive (true);
             GUISlots.transform.position = new Vector3 (SelectedSlot.transform.position.x, SelectedSlot.transform.position.y + 32, 0);
         }
         if (Input.GetAxis("Mouse ScrollWheel") < 0) {
             SelectDisappearTimer = 0;
             SelectedSlotNumber += -1;
             GUISlots.SetActive (true);
             GUISlots.transform.position = new Vector3 (SelectedSlot.transform.position.x, SelectedSlot.transform.position.y + 32, 0);
         }
         if (SelectedSlot != null && SelectDisappearTimer >= 300){
             SelectedSlot = null;
             GUISlots.SetActive (false);
         }
 
 
 
         if (Input.GetKeyDown (ButtonToPickup)){
             LookingAt = VarStatsManagerScript.LookingAt;
             VarPropertiesScript = LookingAt.GetComponent<PropertiesScript> ();
             if (VarPropertiesScript.Pickupable == true && PutInInv == null && LookingAt != null){
                 PutInInv = VarStatsManagerScript.LookingAt;
             }
 
         if (Input.GetKeyDown (ButtonToOpenInventory)){
                 if (InventoryUI.activeSelf == false) {
                     InventoryUI.SetActive (true);
                 } else {
                     InventoryUI.SetActive (false);
                 }
             }
         }
     }
 }
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 $$anonymous$$ · Oct 21, 2017 at 06:06 PM 0
Share

Issue is probably between lines 126 and 141.

avatar image $$anonymous$$ · Oct 21, 2017 at 07:13 PM 0
Share

Why was this moved to moderation?

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

119 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

Related Questions

Question about an inventory system idea 2 Answers

Grid Inventory : Move Item & Slot Highlighting 2 Answers

Using a game object as a UI image for inventory slots 1 Answer

Unity UI constant physical size one image 0 Answers

Turn Another UI image on and off with a Single UI Button 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