I have a variable slots
of Type Slot
which is a vector of 72 Slot
, I made sure that none of the objects Slot
is null, but my loop is stopping at the iteration 16 (in other words gridArray
at position [1,9]
, can somebody help?
public class InventorySystem : MonoBehaviour
{
[SerializeField] private Slot[] slots = new Slot[72];
[SerializeField] private GameObject InventoryUI;
private Slot[,] gridArray;
// Defines the position of slots in the inventory grid
private void DefinePosition(float panelWidth, float slotWidth, int[] panelPadding, float slotSpaceX)
{
float currentWidthOcupiedPerLine = 0;
float gridWidth = panelWidth - panelPadding[0] - panelPadding[1];
slotWidth = slotWidth + (slotSpaceX / 2);
int numColumns = Mathf.FloorToInt(gridWidth / slotWidth);
//int numRows = Mathf.CeilToInt((float)slots.Length / numColumns);
int numRows = 0; // Inicializa o número de linhas como 0
//calcules the number of necessary rows
for (int i = 0; i < slots.Length; i++)
{
currentWidthOcupiedPerLine += slotWidth;
if (currentWidthOcupiedPerLine >= gridWidth)
{
currentWidthOcupiedPerLine = 0;
numRows++; // Incrementa o número de linhas
}
}
Debug.Log(numColumns + ", " + numRows + "bau baun baun bauynbaunbaun hehe");
// Inicializa o gridArray com as dimensões corretas
gridArray = new Slot[numRows, numColumns];
int row = 0;
int column = -1;
Debug.Log(slots.Length + "caucau " + "asas");
for (int i = 0; i < slots.Length; i++)
{
currentWidthOcupiedPerLine += slotWidth;
if (currentWidthOcupiedPerLine >= gridWidth)
{
currentWidthOcupiedPerLine = 0;
row++;
column = 0;
Debug.Log(string.Format("linha {0} {1}", row, column));
gridArray[row, column] = slots[i];
continue;
}
column++;
Debug.Log(string.Format(" {0} {1}", row, column));
gridArray[row, column] = slots[i];
}
}
private void Awake()
{
for (int i = 0; i < slots.Length; i++)
{
if (slots[i].ItemInSlot == null)
{
slots[i].transform.GetChild(0).gameObject.SetActive(false);
}
}
Debug.Log("a");
DefinePosition(870, 90, new int[] { 10, 0 }, 5);
}
}
In this linegridArray = new Slot[numRows, numColumns];
is being defined with 8 rows and 9 columns