void NetDropWeapon() { Rigidbody weaponRigidbody = _heldWeapon.GetComponent <Rigidbody>(); weaponRigidbody.isKinematic = false; weaponRigidbody.AddTorque(_heldWeapon.transform.forward * 4.0f); _heldWeapon.Drop(); _heldWeapon.transform.SetParent(null); OnWeaponDropped?.Invoke(_heldWeapon); _heldWeapon = null; }
// -------------------------------------------------------------------------------------------- // Name : DropWeaponItem // Desc : Drop the weapon at the specified mount into the scene // -------------------------------------------------------------------------------------------- public override void DropWeaponItem(int mountIndex, bool playAudio = true) { if (mountIndex < 0 || mountIndex >= _weapons.Count) { return; } // Chck we have a valid BackPack mount in the inventory InventoryWeaponMountInfo itemMount = _weapons[mountIndex]; if (itemMount == null || itemMount.Weapon == null) { return; } // This is the weapon we want to drop InventoryItemWeapon weapon = itemMount.Weapon; // Drop it into the scene Vector3 position = _playerPosition != null ? _playerPosition.value : Vector3.zero; position += _playerDirection != null ? _playerDirection.value : Vector3.zero; CollectableWeapon sceneWeapon = weapon.Drop(position, playAudio) as CollectableWeapon; if (sceneWeapon) { // Copy over instance data from mount into proxy sceneWeapon.condition = itemMount.Condition; sceneWeapon.rounds = itemMount.InGunRounds; } // Nullify the slot so it is empty _weapons[mountIndex].Weapon = null; // Broadcast event that this weapon has been dropped OnWeaponDropped.Invoke(weapon); }