- Home /
load c# script from server
Hi. I want download c# script from URL and load it in my game on runtime.
I know how to use www class to download script and store it in SD card. But how can I load this script to android game?
Thanks so much
Answer by Magius96 · Mar 07, 2016 at 03:33 PM
I don't know if what you are asking can actually be done because you don't have the compiler available at runtime for compiling and interpreting the script. Perhaps it would be better if you looked into including a scripting engine in your project so that you can use scripts instead of C#. That is, unless you intend to write a C# parser for your game.
Perhaps something like MoonSharp: https://www.nuget.org/packages/MoonSharp Or UniLua: https://github.com/xebecnan/UniLua
UniLua is designed specifically for Unity3D, where MoonSharp is designed for .NET and has proven compatible for Unity3D.
Answer by rushikesh988 · Mar 08, 2016 at 09:57 AM
Hi @vahid62,
You can't do that directly but you might want to look into assetbundles. You can include scripts into assetbundles.
Visit Here:
http://docs.unity3d.com/Manual/scriptsinassetbundles.html
QuickView:
If you want to include code in your AssetBundles that can be executed in your application it needs to be pre-compiled into an assembly and loaded using the Mono Reflection class (Note: Reflection is not available on platforms that use AOT compilation, such as iOS). You can create your assemblies in any normal C# IDE (e.g. Monodevelop, Visual Studio) or any text editor using the mono/.net compilers.Note: Loading scripts from asset bundles is not supported on Windows Store Apps and Windows Phone.
Answer by Silverfell · Mar 08, 2016 at 01:19 PM
Based on your other replies, you might want to look into loading and saving JSON objects that contain the details of all your objects.
By saving a JSON file that basically holds the catalog of your items, their preview pictures, 3d models and whatever else you need, you can then always just load it up in your game and download what you don't already have.
To be clear, the JSON could look something like this:
[
{
'ID:1': {
name: 'name',
picture: 'here',
model: 'it is here'
},
'ID:2': {
name: 'name',
picture: 'here',
model: 'it is here'
},
'ID:3': {
name: 'name',
picture: 'here2',
model: 'it is here'
},
'ID:4': {
name: 'name',
picture: 'here',
model: 'it is here'
}
}
]
I am talking about JSON because Unity has a nifty new JSON serializer you can use. If you don't like JSON, you can save your data as XML, flat text, or even in a database. While everyone is perfectly correct in stating that you can't load C# files without a new build, you sure can download anything else you can get your hands on.
Answer by CptCheerios · Mar 07, 2016 at 03:37 PM
You can't load a script outside of the project. It needs to be compiled. What are you trying to accomplish, maybe there is a different way to accomplish it than this.
Thanks for replies. $$anonymous$$y project is a 3d catalog application. I have made many scenes and each scene has a 3d model ,animations and several scripts.
In the future i will want to add new models and scripts to this catalog and these assets all will be loaded from a server.
I don't want users have to be forced to download new version each time new model is added.
With assets bundle I can create each scene as a .unity3d file and upload it on server and load it in application and it works well but scripts are missing.
and yes the problem is script that must be compiled before in unity engine. so how can I do it?
Hey I am facing the similar kind of issue have you figured out a way to accomplish this?
Your answer
Follow this Question
Related Questions
my textures aren't working (bmp files issue) 3 Answers
How to load a script at runtime? 0 Answers
load in Hierarchy 1 Answer
How can I programatically load a .pcx file in my script? 1 Answer
I think I abuse of Ressources.load 2 Answers