Skip to content

develop HUD UI

Jeon-YJ1004 edited this page Mar 31, 2023 · 3 revisions

image image image image

[SlotUI.cs]
public class SlotUI : MonoBehaviour
{
    public enum slotType { Weapon,Accessory} //0 ,1
    GridLayoutGroup grid;
    GameObject slotprefab;
    public GameObject list;
    private void Awake()
    {
        grid = gameObject.GetComponent<GridLayoutGroup>();
    }
    public void AddSlot(int index,int type)
    {
        string resourceName;
        switch (type)
        {
            case 0:
                resourceName = "Weapons/"+index;
                slotprefab = Resources.Load<GameObject>(resourceName);
                break;
            case 1:
                resourceName = "Accessory/" + index;
                slotprefab = Resources.Load<GameObject>(resourceName);
                break;
        }
        GameObject slot=(GameObject)Instantiate(slotprefab);
        slot.transform.SetParent(list.transform);
    }
}


[EquipmentManagementSystem.cs]

 public void Set(int startingWeapon){
        GetWeapon(startingWeapon);
}
 public void GetWeapon(int weaponIndex)
    {
        .
        .
        .
        GameManager.instance.WeaponSlot.GetComponent<SlotUI>().AddSlot(weaponIndex, 0);
    }
Clone this wiki locally