IEnumerator CreateItem() { // create the random ammo, and heals, then the weapons List <Constants.AMMO_TYPE> ammos = Enum.GetValues(typeof(Constants.AMMO_TYPE)) .Cast <Constants.AMMO_TYPE>() .ToList(); List <Constants.WEAPON_TYPE> weapons = Enum.GetValues(typeof(Constants.WEAPON_TYPE)) .Cast <Constants.WEAPON_TYPE>() .ToList(); for (int i = 0; i < ammoToCreate; i++) { yield return(new WaitForSecondsRealtime(secondsBetweenSpawn)); int randomIndex = UnityEngine.Random.Range(0, (ammos.Count - 1)); Constants.AMMO_TYPE newAmmo = ammos[randomIndex]; AmmoInfoScriptable ammo = WeaponSpawnManager.instance.GetAmmoInfo(newAmmo); CreateInstance(ammo.pickableAmmoPrefab); } for (int i = 0; i < healToCreate; i++) { yield return(new WaitForSecondsRealtime(secondsBetweenSpawn)); // only one type of heal at this point CreateInstance(healthPrefab); } for (int i = 0; i < weaponsToCreate; i++) { yield return(new WaitForSecondsRealtime(secondsBetweenSpawn)); GameObject weaponToCreate = null; if (randomWeapon) { int randomIndex = UnityEngine.Random.Range(0, (weapons.Count - 1)); Constants.WEAPON_TYPE wType = weapons[randomIndex]; WeaponInfoScriptable weaponInfo = WeaponSpawnManager.instance.GetWeaponInfo(wType); weaponToCreate = weaponInfo.pickableWeaponPrefab; } else { weaponToCreate = prefabToCreate; } CreateInstance(weaponToCreate); } }
/// <summary> /// Prepare all the UI for the posible ammos /// </summary> public void PrepareAmmoUI() { foreach (Constants.AMMO_TYPE ammoType in (Constants.AMMO_TYPE[])Enum.GetValues(typeof(Constants.AMMO_TYPE))) { Ammo ammoInfo = new Ammo(); if (WeaponSpawnManager.instance) { AmmoInfoScriptable ammoScriptableInfo = WeaponSpawnManager.instance.GetAmmoInfo(ammoType); if (ammoScriptableInfo) { ammoInfo.info = ammoScriptableInfo; // create the instances of the icon and equiped ammo in the canvas ammoInfo.ammoIcon = Instantiate(ammoInfo.info.ammoIcon, allAmmoPanel.transform); ammoInfo.text = ammoInfo.ammoIcon.GetComponent <Text>(); ammoInfo.text.text = InventoryManager.instance.GetAvailableAmmo(ammoInfo.info.ammoType).ToString(); ammoInfo.ammoUIEquiped = Instantiate(ammoInfo.info.ammoUIPrefab, equipedAmmoPanel.transform); ammoInfo.equipedAmmoText = ammoInfo.ammoUIEquiped.GetComponent <Text>(); ammoInfo.ammoUI = ammoInfo.ammoUIEquiped.GetComponent <AbstractUIAmmo>(); ammoInfo.ammoUIEquiped.SetActive(false); //disable the equiped ammo, later active the actual Weapon ammoList.Add(ammoInfo); } } } }