Executing Code on Event passed via Class

Hey,
I have a question on what would be the best architectural way to solve a problem:

I have a first person 3D game. In the level are different items the player can pick up. Now I want to execute code every time a player picks up an item. I would like to have a class called “PickupManager” which takes care about all the interactions, animations and so on. To this class I would like to pass some script/code via variable that I can assign in the Unity Editor. On pickup my “PickupManager” class would then be executing the code/script passed via variable.

Is this possible? What would be the best way to do this?
I tried the MonoScript object, however this is only avaiable in the editor and not in the builded game.

Best regards
Puffin

First, welcome to the unity forum!

Second, I think taking a look into ScriptableObjects might help you to do what you want. They are classes which can be stored as an asset. These assets can then be dragged into your PickupManager in the editor.

If you want the best architectural way, then you shouldn’t use managers, forget that postfix. There is no strict responsibility for manager, you mentioned yourself that this class will do everything, this is against all architectural principles and isn’t the best, but bad way.

Why do you need some script to be dragged from the inspector? Why can’t you use usual Action/UnityAction event in Pickup script and subscribe to it from another script on same GameObject?