Is it possible to add scripts during runtime to a game object to add new functionality or would I have to have a factory that spawns a separate game object that contains the new script that I want to add?
You can load and execute scripts via other scripts at runtime. Check these posts
The script is regular script file, so I don’t have to load it during runtime. I just wondered if there was an automated way to just add a script that automatically gets the init(), update() and final() callbacks.
You can load and run code at run-time using the links provided by pkeod, but I consider that solution better suited for downloading and running patched code or similar.
Is that what you want to do, or is it rather like you having a couple of pre-defined and at compile time known snippets of code that should be used run-time under certain conditions? If it’s the latter case then I’d have a script file require one or more modules with code and forward init(), update() and similar life cycle messages to the modules depending on some run-time condition.
The scripts I was thinking about would be static and bundled. I was just wondering if there was a way to skip the forwarding, since it adds manual steps that might be missed when they are reused later.
I might try with a factory and see how it goes or just skip it entirely then.