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);
        }
    }
示例#2
0
 /// <summary>
 /// Show a pickable weapon info in the center of screen
 /// </summary>
 /// <param name="weaponType"></param>
 public void ShowWeaponInfo(Constants.WEAPON_TYPE weaponType)
 {
     if (WeaponSpawnManager.instance)
     {
         WeaponInfoScriptable info = WeaponSpawnManager.instance.GetWeaponInfo(weaponType);
         if (info)
         {
             if (info.equipedWeaponIcon)
             {
                 centeredImage.sprite = info.equipedWeaponIcon;
                 centeredImage.gameObject.SetActive(true);
             }
             if (info.name != null)
             {
                 centeredText.text = info.name;
             }
         }
     }
 }
    /// <summary>
    ///  Instantiate a new Pickable item weapon in the World, in the transform position/rotation
    ///  CAN instantiate a totally NEW weapon (specifing the type) or a pickable with a weapon inside
    ///  for example a droped weapon with half ammo, cant edit the prefab, so we attach the real weapon
    /// </summary>
    /// <param name="pointToSpawn"> The position in the world where drop the weapon, is the transform of the spawnPoint</param>
    /// <param name="instantiateNew"> if FALSE: the new pickableWeapon contains an GameObject of weapon, if TRUE contains a PREFAB</param>
    /// <param name="weaponType"> The Kind of weapon, to search in the list of weaponlist</param>
    /// <param name="weapon">The GameObject of an instantiated weapon, in case of not creating a prefab</param>
    public void InstantiateWeapon(Transform pointToSpawn, bool instantiateNew, Constants.WEAPON_TYPE weaponType, GameObject weapon)
    {
        WeaponInfoScriptable weaponInstantiate = null;
        bool found = false;

        foreach (WeaponInfoScriptable wInfo in weaponInfoList)
        {
            if (wInfo.weaponType == weaponType)
            {
                weaponInstantiate = wInfo;
                found             = true;
            }
        }
        if (found)
        {
            GameObject newPickable;
            newPickable = Instantiate(weaponInstantiate.pickableWeaponPrefab);
            newPickable.transform.position = pointToSpawn.position;
            newPickable.transform.rotation = pointToSpawn.rotation;

            if (instantiateNew)
            {
                // the new drop is a pickable from PREFAB, so the prefab already contains the prefabweapon, do nothing
                //just secure that the weapon has not an objectattached
                newPickable.GetComponent <Pickable>().weaponAttached = null;
            }
            else
            { // IS AN ACTUAL WEAPON  ON THE MAP!!! NOT A PREFAB
                // is not a instance of prefab? no new item? then is a already instantiated weapon, attach to the
                // pickable
                weapon.GetComponent <AbstractWeapon>().active        = false; // just in case disable the weapon
                newPickable.GetComponent <Pickable>().weaponAttached = weapon;
                //we have move the weapon from the player, to the gameObject
                weapon.transform.SetParent(newPickable.transform);
            }
            newPickable.GetComponent <Rigidbody>().AddForce(transform.forward * 10);
            // now with the pickable push it into the real world
        }
    }
示例#4
0
    /// <summary>
    /// Show in the actual equip weapon the icon
    /// </summary>
    /// <param name="weaponType"></param>
    public void SetEquipedWeapon(Constants.WEAPON_TYPE weaponType)
    {
        WeaponInfoScriptable info = WeaponSpawnManager.instance.GetWeaponInfo(weaponType);

        equipedWeaponIcon.sprite = info.equipedWeaponIcon;
    }