So, I have a UI panel, and I need to create UI images inside it, so I created a prefab, that´s properly anchored, but when I run my scrip, it keeps creating the images from the center point, and not from the top left as the used prefab is set
using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour {
public GameObject slotsPrefab;
public int slotRows;
public int slotCollumns;
int x, y;
float invX, invY;
// Use this for initialization
void Start () {
invX = slotCollumns + 8;
invY = slotRows + 8;
for (int i = 1; i < slotRows + 1; i++) {
for (int j = 1; j < slotCollumns + 1; j++) {
GameObject slot = (GameObject)Instantiate(slotsPrefab);
slot.transform.SetParent(this.gameObject.transform);
slot.GetComponent<RectTransform>().anchoredPosition = new Vector2(0,0);
slot.GetComponent<RectTransform>().localPosition = new Vector3(x, y, 0);
x = x + 32;
if (j == slotCollumns) {
x = -130;
y = y - 32;
}
}
}
}
}
well, so I dont know why it keeps creating them from the center… I also want to know how can I set the UI panel height and width… thank you!