Inventory System Help

Hi, I’m making a RPG-like game, and I’d like some help on what’s going wrong on my inventory system. Right now, it kind of works. What I mean is sometimes it will work fine, but other times it won’t at all. Basically, sometimes when I click the pickup item it registers and goes into the inventory, and it fills the spot and checks the boolean. But sometimes it requires both items in the hierarchy to be active for the boolean to be true. Here is the inventory space code:

#pragma strict

var isEmpty : boolean;

var items : GameObject[];

function Update () {

	for(var i = 0; i < items.Length; i++) {
		if(items*.activeInHierarchy) {*
  •  	break;*
    
  •  	isEmpty = false;*
    
  •  }*
    
  •  else {*
    
  •  	isEmpty = true;*
    
  •  }*
    
  •  return;*
    
  • }*
    }
    And the item pickup code:
    #pragma strict

var inventorySpace : InventorySpace[];

var objs : GameObject[];

function OnMouseDown () {

  • for(var i = 0; i < inventorySpace.Length; i++) {*
    _ if(inventorySpace*.isEmpty) {_
    _ objs.active = true;
    inventorySpace.isEmpty = false;
    break;
    }
    }
    }*

    Any help would be greatly appreciated!_

the problem i see is:

  1. you are using break before making isEmpty false
  2. and you are returning as soon as the if statement is finished

check this code and see if it runs

#pragma strict
 
 var isEmpty : boolean;
 
 var items : GameObject[];
 
 function Update () {
     for(var i = 0; i < items.Length; i++) {
         if(items*.activeInHierarchy) {*

isEmpty = false;
break;
}

else {
isEmpty = true;
}
}
}

Switch lines 11 and 12 in your first script. When the code hits the ‘break’ code, it wont reach everything else that is after it. This might be your problem.