0

I've searched through the web and seen a lot of talk about a WWW method of retrieving content from a web server or a database and using values but I would like a method where I don't have to continuously update my code in monodevelop and then build the projects as big projects sometimes take up to an hour to build so basically patching over a server.

So can the WWW method be used to do this? Like for instance lets say I have a code like this

int level;
int currentLevel;
if(level != currentLevel){
 level = currentLevel;
}

Now this code is having complications because the level is not always up to date and I have to change methods into something like this so tht the level stays updated

int level;
int currentLevel;
private void Update(){
 if(level != currentLevel){
  level = currentLevel;
 }
}

Now instead of rebuilding my entire project I would like to put this in maybe a database or some sort and then when the game launches it checks the database to make sure the code matches the code on the database if the code matches then it starts the game if not it updates

FYI I am building for WebGL HTML5

gman
  • 100,619
  • 31
  • 269
  • 393
  • 1
    as Programmer explains, it's absolutely impossible to do this. completely rethink it! – Fattie May 21 '16 at 12:13
  • please see the comment i left on his answer –  May 21 '16 at 15:49
  • 1
    the simple answer to your question is you can't ***update*** "code" in any way whatsoever. OK? you can of course simply download entirely new or different levels; those new levels would include their own code. But it's utterly impossible to "change" or "edit" code. – Fattie May 21 '16 at 16:28

1 Answers1

2

You can't do that. What you can do is to make make a decision based on what you receive from WWW but the action to do must exist already before it can used. You can't create a new action during run-time.

For example, make decision if ad should be displayed in your app.

WWW www = new WWW("url");
yield return  www;

if(www.text=="AdEnabled"){
    displayAd();
}

You can also run JavaScript code from Unity but that's not helpful to your question. You can't do more than that.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • There is a way my son has a game he plays called wizard101 and anytime they update thier game it has a progressbar where it shows its downloading the new material and such in the time he has had this game it has been updated with new stuff numerous times and i have never had to update the client so i know its possible –  May 21 '16 at 15:48
  • 2
    Sure, you do that with **asset bundles**. Note that it is simply downloading ***a whole new scene***. (That scene could include new code of course, new images, new music, indeed it could be an entirely new game.) So you can't ***change*** code. But sure, you can simply download new levels, whole new games, new characters and so on. You'll have to learn about Asset Bundles in Unity. Cheers! – Fattie May 21 '16 at 16:27
  • @JoséphFlames Listen to Joe. You can change graphics with code(decision I mentioned above) or with Asset but you can't change your code during run-time with WWW. If new features other than new scene and graphics/audio were added to the wizard101 game, then the exe or dll file must have been modified by the programmers and **re-compiled**. It must be **re-compiled** for it to work. Again, modifying the code requires recompiling it ans you can't do that with WWW. – Programmer May 21 '16 at 17:32
  • WWW was just something i have heard about but i mean how would I go about this asset bundle thing mind updating your answer with good reliable information and I will accept it –  May 21 '16 at 23:06
  • @JoséphFlames Your question is about modifying code which I answered. Editing code and loading AssetBundle from url are totally un-related. If I modify my answer and add info about AssetBundle, it will make your question look like what you are asking is possible. To learn more about AssetBundle, go here http://docs.unity3d.com/ScriptReference/AssetBundle.html It has more info and examples than I can post here. – Programmer May 22 '16 at 01:28
  • so lets say i have a menu scene could i update that scene with new code and download it to the game using this asset bundle method? –  May 22 '16 at 04:54
  • @JoséphFlames I believe you can load scripts from Assets but you can't change what is in the script or old one. Please understand that you can't download scripts on iOS or Android. I can't remember which one but if you do, your developer account will be terminated. Just a notice for you. – Programmer May 23 '16 at 04:12