davooo0
November 7, 2013, 11:26am
1
This is for an inventory system i need help converting some code to make it go through a for loop and make the slots based on a pre defined number of slots
GUI.Box(Rect(SlotOne),"1");
GUI.Box(Rect(SlotTwo),"2");
GUI.Box(Rect(SlotThree),"3");
GUI.Box(Rect(SlotFour),"4");
GUI.Box(Rect(SlotFive),"5");
GUI.Box(Rect(SlotSix),"6");
GUI.Box(Rect(SlotSeven),"7");
GUI.Box(Rect(SlotEight),"8");
thats just for the quick slots now i want the inventory to be like minecraft and writing out the boxes one by one will take too long
thanks
I’m not proficent at UnityScript, but I have tried to translate it by checking the reference manual. Please, be aware of possible minor syntax errors.
import System.Linq;
var slots : Rect[];
var slotCount: int;
function Start()
{
var halfCount = slotCount/2;
slots = Enumerable.Range(0, slotCount)
.Select(function(i)
Rect((Screen.width/ 2) + (i-halfCount)*100 * Xratio,
Screen.height / 2 + 450.0 * Yratio, 82.0 * Xratio, 82.0 * Yratio)
)
.ToArray();
}
function OnGUI()
{
for(int i=0; i<slots.Length; i++)
{
GUI.Box(slots*, (i+1).ToString());*
}
}