Hi guys,
I’ve made a couple of classes to execute commands (Command, SequentialCommands, ParallelCommands)
I have a prefab where I set all the commands to execute in the initialization of my app.
I have to execute them in parallel or sequential depending on the command.
So I have in my initialization class something like this,
public List commands;
But, in the editor I can’t drag scripts… only gameobject. Is there a way to add scripts?
I hope I am clear.
Thanks
When you say you want to drag in scripts, are you saying you want to drag your script file from the project folder, and use the class itself?
That’s not possible because the scripts aren’t objects (they’re classes), but what you can do (with your existing code) is attach the desired script to your GameObject, then drag it from there into your array.
1 Like
Thank you very much! That works for me!
The other two solutions would be:
- Inherit from ScriptableObject. They work similar to MonoBehaviour, but are not tied to a GameObject, instead they are project assets, which can contain data and methods. They can be dragged into regular ObjectFields.
- Save a string reference to the class name and create an instance at runtime via the C# Activator class.
The GameObject/Prefab way works of course, but it feels weird to create an object with a Transform and then make a prefab of it only to access a method in code. If you also want to serialize data, which you can tweak in the inspector it makes sense to use a ScriptableObject.
Awesome! Thank you! I’ll try that