Currently I’ve created some weapons (e.g. longsword, spear) as prefabs. These consist of a sprite with a Weapon script attached, specifying attributes about the weapon (weight, cost, damage etc.)
What I want is to allow the player to:
-
Have multiple “local” instances of these weapons, NOT just references to the prefabs.
-
Customise these “local” weapons by changing their properties (e.g. adding fire damage).
But I’m struggling to do this because any changes I make to weapons affect the base prefab, which I don’t want.
I know that GameObject.Instantiate creates a copy of the prefab in the scene; ultimately I do this when I want a weapon to actually be equipped, but it seems silly to instantiate all my weapons in the scene and have all but one of them sitting somewhere deactivated. The other thing I was thinking is that I could have a list of the player’s current weapons, which consists of deep copies of the prefabs, and operate on that.
Basically if I have a longsword in my inventory, I don’t want my customisations to that longsword to apply to ALL longswords (by affecting the base prefab), I only want it to affect that particular longsword. What’s the best way of doing this?