Beispiel #1
0
        /// <summary>
        /// Changes the character's current weapon to the one passed as a parameter
        /// </summary>
        /// <param name="newWeapon">The new weapon.</param>
        public virtual void ChangeWeapon(Weapon newWeapon, string weaponID, bool combo = false)
        {
            // if the character already has a weapon, we make it stop shooting
            if (CurrentWeapon != null)
            {
                if (!combo)
                {
                    ShootStop();
                    if (_weaponAim != null)
                    {
                        _weaponAim.RemoveReticle();
                    }
                    Destroy(CurrentWeapon.gameObject);
                }
            }

            if (newWeapon != null)
            {
                if (!combo)
                {
                    CurrentWeapon = (Weapon)Instantiate(newWeapon, WeaponAttachment.transform.position + newWeapon.WeaponAttachmentOffset, WeaponAttachment.transform.rotation);
                }
                CurrentWeapon.transform.parent         = WeaponAttachment.transform;
                CurrentWeapon.transform.localPosition += newWeapon.WeaponAttachmentOffset;
                CurrentWeapon.WeaponID = weaponID;
                _weaponAim             = CurrentWeapon.GetComponent <WeaponAim>();

                // we turn off the gun's emitters.
                CurrentWeapon.Initialization();
                CurrentWeapon.InitializeComboWeapons();
                CurrentWeapon.InitializeAnimatorParameters();
            }
            else
            {
                CurrentWeapon = null;
            }
        }