Ejemplo n.º 1
0
        private int tempWeapReturnID = 0;       //a cache to store the default weaponID when using temporary weapon
        public void AddWeapon(Weapon prefab, bool replaceWeapon = false, bool temporary = false, float temporaryTimer = 30)
        {
            GameObject obj = MountWeapon((GameObject)Instantiate(prefab.gameObject));

            //replace weapon and temporary are mutually exclusive
            if (replaceWeapon)
            {
                Destroy(weaponList[weaponID].gameObject);
                weaponList[weaponID] = obj.GetComponent <Weapon>();

                TDS.NewWeapon(weaponList[weaponID], weaponID);
            }
            else if (temporary)
            {
                tempWeapReturnID = weaponID;
                weaponList[weaponID].gameObject.SetActive(false);

                if (weaponList[weaponID].temporary)
                {
                    RemoveWeapon();
                }

                weaponID = weaponList.Count;
                weaponList.Add(obj.GetComponent <Weapon>());

                weaponList[weaponList.Count - 1].temporary = true;
                if (temporaryTimer > 0)
                {
                    StartCoroutine(TemporaryWeaponTimer(weaponList[weaponList.Count - 1], temporaryTimer));
                }
            }
            else
            {
                weaponID = weaponList.Count;
                weaponList.Add(obj.GetComponent <Weapon>());
                TDS.NewWeapon(weaponList[weaponID]);
            }

            weaponList[weaponID].Reset();

            TDS.SwitchWeapon(weaponList[weaponID]);
        }