Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Error in Inventory Script

$
0
0
Heya, So I'm trying to build an inventory system in C#, And so far its mostly working, Its just whenever I have only One object and remove it from the Inventory I get the error ArgumentOutOfRangeException: Argument is out of range. Parameter name: index using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; public class Inventory : MonoBehaviour{ public List inventory = new List(); //Reference Data // Ui display Objects bool _Isactive; public GameObject InventoryMenu; public GameObject ItemButton; public GameObject InventoryDisplay; public Text ItemNameDisplay; public Text ItemDescDisplay; //Equipment Slots public BaseItem HeadSlot; public BaseItem ChestSlot; public BaseItem LegSlot; public BaseItem BootSlot; public BaseItem WeaponSlot; // Base Item used For item Transference void Start () { } void Update () { if (Input.GetKeyDown (KeyCode.Tab)) { _Isactive =! _Isactive; if (_Isactive == true) { InventoryMenu.SetActive (true); PopulateList (); } if (_Isactive == false) { ClearDisplayList (); InventoryMenu.SetActive (false); } } } public void PopulateList(){ for (int i = 0; i < inventory.Count; i++) { int Index = i; GameObject button = (GameObject)Instantiate (ItemButton); button.GetComponentInChildren ().text = "" + inventory [i].itemName; button.GetComponent ().Item_Name = "" + inventory [i].itemName; button.GetComponent ().Item_Desc = "" + inventory [i].itemDesc; button.transform.SetParent (InventoryDisplay.transform,false); button.GetComponent

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>