Move Inventory Methods to base Character class

This commit is contained in:
Louis Hobbs 2023-02-12 20:33:08 +00:00
parent ecff0b36a8
commit 44f69a4355
2 changed files with 23 additions and 1 deletions

View File

@ -154,6 +154,19 @@ void ANakatomiCharacter::AddWeaponToInventory(TSubclassOf<class AWeapon> weapon)
} }
} }
void ANakatomiCharacter::AddWeaponToInventory(AWeapon* weapon)
{
weapon->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, "WeaponHand");
weapon->SetActorEnableCollision(false);
weapon->SetActorHiddenInGame(true);
WeaponInventory.Add(weapon);
if (WeaponInventory.Num() == 1)
{
SetCurrentWeapon(WeaponInventory[0]);
}
}
AWeapon* ANakatomiCharacter::InitializeWeapon(TSubclassOf<class AWeapon> weapon) AWeapon* ANakatomiCharacter::InitializeWeapon(TSubclassOf<class AWeapon> weapon)
{ {
FActorSpawnParameters SpawnParameters; FActorSpawnParameters SpawnParameters;
@ -189,3 +202,8 @@ void ANakatomiCharacter::SetCurrentWeapon(AWeapon* weapon)
CurrentWeapon->SetActorHiddenInGame(false); CurrentWeapon->SetActorHiddenInGame(false);
} }
} }
int ANakatomiCharacter::GetCurrentInventorySlot()
{
return CurrentInventorySlot;
}

View File

@ -63,6 +63,8 @@ public:
void AddWeaponToInventory(TSubclassOf<class AWeapon> weapon); void AddWeaponToInventory(TSubclassOf<class AWeapon> weapon);
void AddWeaponToInventory(AWeapon* weapon);
void RemoveWeaponFromInventory(int i); void RemoveWeaponFromInventory(int i);
void RemoveWeaponFromInventory(AWeapon* weapon); void RemoveWeaponFromInventory(AWeapon* weapon);
@ -74,4 +76,6 @@ public:
AWeapon* GetCurrentWeapon(); AWeapon* GetCurrentWeapon();
void SetCurrentWeapon(AWeapon* weapon); void SetCurrentWeapon(AWeapon* weapon);
int GetCurrentInventorySlot();
}; };