feat: make weapons switchable

This commit is contained in:
Chris
2026-01-16 17:40:32 -05:00
parent 6c3317014a
commit ca54b5b960
7 changed files with 110 additions and 32 deletions

View File

@@ -11,7 +11,7 @@ namespace Reset.Units{
private IEquipable currentWeapon;
private GameObject currentWeaponItem;
public void OnDrawWeapon(){
public void DrawWeapon(){
if (Unit.UnitIsNetworked()) {
CreatePlayerWeaponRpc();
} else {
@@ -28,20 +28,36 @@ namespace Reset.Units{
// Remove a current weapon
DisposeCurrentWeapon();
// Reference inventory and inventory
PlayerInventory playerInventory = Unit.Inventory as PlayerInventory;
PlayerAnimation playerAnimation = Unit.Animation as PlayerAnimation;
// Remove a current weapon
if (currentWeapon != null) {
Destroy(currentWeaponItem);
currentWeaponItem = null;
}
// Switch which weapopn gets pulled out
Weapon weaponType = null;
switch ((Unit.Combat as PlayerCombat).currentCombatType) {
case CombatType.Melee:
weaponType = ((PlayerInventory)Unit.Inventory).meleeWeapon;
break;
case CombatType.Ranged:
weaponType = ((PlayerInventory)Unit.Inventory).rangedWeapon;
break;
default:
throw new ArgumentOutOfRangeException();
}
// Add weapon to status and hand
currentWeapon = playerInventory.meleeWeapon;
currentWeaponItem = playerInventory.meleeWeapon.InstantiateItemObject();
currentWeapon = weaponType;
currentWeaponItem = weaponType.InstantiateItemObject();
// Move item to hand
currentWeaponItem.transform.SetParent(playerAnimation.rightHand);
currentWeaponItem.transform.localPosition = playerInventory.meleeWeapon.handPositionOffset;
currentWeaponItem.transform.rotation = playerAnimation.rightHand.rotation * Quaternion.Euler(playerInventory.meleeWeapon.handRotationOffset);
// Add related weapon's actor script
currentWeaponItem.transform.SetParent((Unit.Animation as PlayerAnimation).rightHand);
currentWeaponItem.transform.localPosition = weaponType.handPositionOffset;
currentWeaponItem.transform.rotation = (Unit.Animation as PlayerAnimation).rightHand.rotation * Quaternion.Euler(weaponType.handRotationOffset);
// Add the weapon script for this weapon
(currentWeapon as Weapon).AddActorScript();
}
@@ -49,7 +65,7 @@ namespace Reset.Units{
return currentWeaponItem;
}
public void OnHolsterWeapon(){
public void HolsterWeapon(){
DisposeCurrentWeapon();
}