/// <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();
                    MMAnimator.UpdateAnimatorBool(_animator, CurrentWeapon.EquippedAnimationParameter, false, _character._animatorParameters);
                    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.SetOwner(_character, this);
                CurrentWeapon.WeaponID = weaponID;
                _aimableWeapon         = CurrentWeapon.GetComponent <WeaponAim> ();
                // we handle (optional) inverse kinematics (IK)
                if (_weaponIK != null)
                {
                    _weaponIK.SetHandles(CurrentWeapon.LeftHandHandle, CurrentWeapon.RightHandHandle);
                }
                // we turn off the gun's emitters.
                CurrentWeapon.Initialization();
                CurrentWeapon.InitializeComboWeapons();
                CurrentWeapon.InitializeAnimatorParameters();
                InitializeAnimatorParameters();
                if ((_character != null) && !combo)
                {
                    if (!_character.IsFacingRight)
                    {
                        if (CurrentWeapon != null)
                        {
                            CurrentWeapon.FlipWeapon();
                            CurrentWeapon.FlipWeaponModel();
                        }
                    }
                }
            }
            else
            {
                CurrentWeapon = null;
            }
        }
Exemple #2
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();

                    AnimatorControllerParameter[] parameters = _character._animator.parameters;
                    foreach (AnimatorControllerParameter parameter in parameters)
                    {
                        if (parameter.name == CurrentWeapon.EquippedAnimationParameter)
                        {
                            MMAnimatorExtensions.UpdateAnimatorBool(_animator, CurrentWeapon.EquippedAnimationParameter, false);
                        }
                    }

                    Destroy(CurrentWeapon.gameObject);
                }
            }

            if (newWeapon != null)
            {
                if (!combo)
                {
                    CurrentWeapon = (Weapon)Instantiate(newWeapon, WeaponAttachment.transform.position + newWeapon.WeaponAttachmentOffset, Quaternion.identity);
                }
                CurrentWeapon.transform.SetParent(WeaponAttachment.transform);
                if (ForceWeaponScaleResetOnEquip)
                {
                    CurrentWeapon.transform.localScale = Vector3.one;
                }
                CurrentWeapon.SetOwner(_character, this);
                CurrentWeapon.WeaponID = weaponID;
                _aimableWeapon         = CurrentWeapon.GetComponent <WeaponAim> ();
                // we handle (optional) inverse kinematics (IK)
                if (_weaponIK != null)
                {
                    _weaponIK.SetHandles(CurrentWeapon.LeftHandHandle, CurrentWeapon.RightHandHandle);
                }
                // we turn off the gun's emitters.
                CurrentWeapon.Initialization();
                CurrentWeapon.InitializeComboWeapons();
                CurrentWeapon.InitializeAnimatorParameters();
                InitializeAnimatorParameters();
                if ((_character != null) && !combo)
                {
                    if (!_character.IsFacingRight)
                    {
                        if (CurrentWeapon != null)
                        {
                            CurrentWeapon.FlipWeapon();
                            CurrentWeapon.FlipWeaponModel();
                        }
                    }
                }
            }
            else
            {
                CurrentWeapon = null;
            }
        }