Inventory implementation
Asked Answered
V

1

0

So i have a firearm class/scene that i inherit from to make new guns and i want to implement for now a simple inventory that stores ammo and weapons.

So i'm wondering Should i have the inventory inside of the player script or should i implement it somewhere else like in a singleton?
The guns will need to interact with the inventory to reload ammo i suppose, so having easy access to the inventory by making it a singleton, could maybe be good? Or should i have the inventory in the Player script and then just have a reference variable to the player in the Gun script so that the Guns have access to the ammo in the inventory?

Not sure what implementation would be good

Vesiculate answered 19/2, 2024 at 19:24 Comment(0)
S
0

I'm partial to creating component systems and then using dependency injection to hook up different systems. In this scenario, my player scene would have a gun component and an inventory component. The gun component would have a reference to inventory component for making queries about ammo. I like this method because I could create an enemy scene and give it the same functionality by including the two components.

Creating an inventory singleton is perfectly acceptable too. Both methodologies are legit solutions.

Serinaserine answered 21/2, 2024 at 3:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.