Destroying weapons we dont need any more

In future parts of this RPG series we’ll implement proper inventory systems, but for now we just need to be able to use various weapons… and of course it helps if we can destroy the old weapon when we pick up a new one.

Is it good way to do this task in Fighter script as below?

this is for Weapon script…

As for me it is easier to understand and implement

Except that ScriptableObjects are a shared resource… meaning that every character that is using the same weapon uses the same Weapon, and the weaponinstance could be referring to any one of them.

That’s why we have to pass the righthandTransform, leftHandTransform, and animator to the Spawn method. Scriptable Objects should not be storing state that isn’t intended to be a shared state.

1 Like

Thank you for explanation! :slightly_smiling_face:

It feels… complicated… at first.

I can see why we need to do this “destroying” by name in Weapon Scriptable Object script. As you said: Scriptable Objects are shared state.

But Beatabout is proposing to destroy the GameObject reference that is stored in Fighter component, that inherits from Monobehaviour. So I think it will work as well.

Although I see the benefits from having the destroying method in Weapon script.

EDIT: ok, I can see now, that currentWeapon is stored as Weapon Scriptable Object class. So it wouldn’t work unless we store in Fighter script reference to weapon GameObject. My bad.

Privacy & Terms