In my personal pursuit of an inventory system for my game, I decided to try doing it from scratch as a learning experiment.
From what I’ve seen on the forums and read in the docs, using a selection grid would not be the way to go, because they’re relatively resource intensive and it doesn’t really suit my needs (only one active button, etc.)
All I’ve done so far is set up the basic grid of GUI buttons, and that alone was pretty confusing!
Here’s what I came up with… is this the easiest way to do achieve what I’m going for?
var inventory : Array;
var inventorySize = 16;
var iconWidthHeight = 50;
var iconOffset = 10;
var iconsPerRow = 4;
function Awake () {
inventory = new Array(inventorySize);
}
function OnGUI(){
var rowCounter : int = 0;
var rowWidth : int = (iconsPerRow*iconWidthHeight)+(iconsPerRow*iconOffset);
for( var i = 0; i < inventory.length; i++ ){
if( ( i%iconsPerRow ) == 0 i > (iconsPerRow-1) ){
rowCounter++;
}
GUI.Button (Rect ( ((i*iconWidthHeight)+(i*iconOffset))-(rowWidth*rowCounter),(rowCounter*iconWidthHeight)+(rowCounter*iconOffset),iconWidthHeight,iconWidthHeight), "");
}
}
[/code]