Okay guys, so I am testing some multiplayer stuff and one of them is placing a house in a terrain. I am new to Unity and coding, so please if you could explain to me why is this error happening and also fix it for me, I would be really thankful.
So after placing the house, the Client receives the message to check if the terrain is available for a house to be placed, if yes, it sends the message to inventory of the player to remove the house from inventory, so it could go to the next thing which is the house showing on the terrain. Anyway, after I place the house and the terrain is available, the house is supposed to get removed from the inventory, but it's not getting removed and I am getting this error:
IndexOutOfRangeException: Array index is out of range.
inventory_player+$RemoveItem$634+$.MoveNext () (at Assets/scripts/inventoryscript/inventory_player.js:915)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
ClientReceive:Remove_Deed(String, String) (at Assets/scripts/ClientReceive.js:2326)
Here is the inventory_player.js code:
913 function RemoveItem(itemNumber : int)
914 {
915 if (Item_Names[itemNumber].ToString() == "") return; // if the slots empty
916 if (DragItem == itemNumber) DragItem = -1;
917 if (itemNumber <= 7) ItemUnEquip(itemNumber);
And here is the ClientReceive.js script:
2319 @RPC
2320 function Remove_Deed(IDNumber : String, house_type : String)
2321 {
2322 if (IDNumber == mainPlayer.GetComponent(playerMain).playerID)
2323 {
2324 Debug.Log(house_type);
2325 var inv : inventory_player = mainPlayer.GetComponent(inventory_player);
2326 inv.RemoveItem(inv.Restest(house_type));
2327 }
2328 }
↧