/// <summary> /// /// </summary> /// <param name="prefab"></param> void PickupWeapon(Weapon prefab) { //TODO : maybe find a better way than comparing name... if (m_Weapons.Exists(weapon => weapon.name == prefab.name)) {//if we already have that weapon, grant a clip size of the ammo type instead ChangeAmmo(prefab.ammoType, prefab.clipSize); } else { var w = Instantiate(prefab, WeaponPosition, false); w.name = prefab.name; w.transform.localPosition = Vector3.zero; w.transform.localRotation = Quaternion.identity; w.gameObject.SetActive(false); w.PickedUp(this); m_Weapons.Add(w); //Example implementation of add a new slot in runtime bl_SlotSwitcher.SlotData sd = new bl_SlotSwitcher.SlotData(); sd.ItemName = w.gameObject.name; sd.Icon = w.weaponIcon; bl_SlotSwitcher.Instance.AddNewSlot(sd); } }
/// <summary> /// /// </summary> private void OnEnable() { //add listener to the change slot event (when press one of the change slot buttons) //in that listener we have to handle the change of the weapon bl_SlotSwitcher.onChangeSlotHandler += OnWeaponChange; //set the starting weapons icons bl_SlotSwitcher.SlotData[] slotsDatas = new bl_SlotSwitcher.SlotData[startingWeapons.Length]; //loop in all the starting weapons in the list for (int i = 0; i < startingWeapons.Length; i++) { //initializated the slot class slotsDatas[i] = new bl_SlotSwitcher.SlotData(); //set the weapon info (name and icon) slotsDatas[i].ItemName = startingWeapons[i]?.gameObject.name; slotsDatas[i].Icon = startingWeapons[i].weaponIcon; } //set the data array to display on the hud bl_SlotSwitcher.Instance.SetSlotsData(slotsDatas); }