Search code examples
c#phphtmlunity-game-engineunity-webgl

Update C# code through website or database


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


Solution

  • 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.