How do I load code dynamically from outside sources?


I am hoping to get some advice on how I can solve a problem I am having with how to load code dynamically into a unity game. To clarify the problem, let me explain an example scenario:

You are playing a game using a client made in Unity. Your character does not do anything because it is your job to make it do something. If code is created outside of the Unity game, how can it be loaded into the game to be used to interact with the “character”.

I am looking for technical details on how I can load this code into a game made with Unity dynamically. I would prefer if the code being imported was written in Javascript or C# and I could use that somehow. I don’t know if the answer has something to do with maybe compiling C# code instead and loading an assembly dynamically.

If any of this is unclear, please respond and I will try my best to clarify.

Thanks for any help,

This is not possible on iOS or the web player - on other platforms you need to create you new functionality and compile it to a DLL.

This can be achieved using a compiler like those shipped with Visual Studio or MonoDevelop or you can use Mono.CSharp DLL to create assemblies from C#.

You can then use one of the Assembly.Load methods to load the assembly into memory, at which time it’s types become available.