protected virtual void HandleWeaponIK() { if (_weaponIK != null) { _weaponIK.SetHandles(CurrentWeapon.LeftHandHandle, CurrentWeapon.RightHandHandle); } _projectileWeapon = CurrentWeapon.gameObject.MMFGetComponentNoAlloc <ProjectileWeapon>(); if (_projectileWeapon != null) { _projectileWeapon.SetProjectileSpawnTransform(ProjectileSpawn); } }
/// <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.SetOwner(_character, this); CurrentWeapon.WeaponID = weaponID; _weaponAim = CurrentWeapon.gameObject.MMGetComponentNoAlloc <WeaponAim>(); // we handle (optional) inverse kinematics (IK) if (_weaponIK != null) { _weaponIK.SetHandles(CurrentWeapon.LeftHandHandle, CurrentWeapon.RightHandHandle); } _projectileWeapon = CurrentWeapon.gameObject.MMFGetComponentNoAlloc <ProjectileWeapon>(); if (_projectileWeapon != null) { _projectileWeapon.SetProjectileSpawnTransform(ProjectileSpawn); } // we turn off the gun's emitters. CurrentWeapon.Initialization(); CurrentWeapon.InitializeComboWeapons(); CurrentWeapon.InitializeAnimatorParameters(); InitializeAnimatorParameters(); } else { CurrentWeapon = null; } }