Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebGL Blank Webpage Get Scene Data

Discussion in 'Editor & General Support' started by kodagames, Jul 9, 2018.

  1. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    Hi,

    What I would like to do and what is possible may be 2 totally different things and Im hoping someone can point me in the right direction. Please see screenshot (which I hope will help illustrate).

    My game (WebGL), has 2 scenes and once the players finishes scene 1, scene 2 will be a replayer for scene 1. I have this part complete.

    Here is the tricky part or the part I need some guidance to point me in the right direction on ways to attempt this:

    Once the finish button is clicked (by the player) I would like the game to be accessible from another webpage (the end users webpage, webpage 2).

    How would one go about this? Is it possible to rename the game file at runtime (from index.html to username/replays/001), I would think this would break the game. Any suggestions on how I should approach this?

    Sure hope someone can give me some guidance on how this could be done.

    Replayer.png
     
  2. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    One thought I just had would be to create a button in the game that calls a JavaScript function in the webpage that creates a new page:
    Code (CSharp):
    1. function makePage(){
    2.     var xmlhttp = new XMLHttpRequest();
    3.     xmlhttp.onreadystatechange = function(){
    4.     if(xmlhttp.readyState==4 && xmlhttp.status==200)
    5.         alert("webpage " + xmlhttp.responseText + " was successfully created!");
    6.     }
    7.     var content = "<html><head><meta charset=\"utf-8\" /> </head><body>new website<script>alert(\"test\")</script></body></html>";
    8.     xmlhttp.open("GET","makePage.php?content=" + content,true);
    9.     xmlhttp.send();
    10. }
    Somehow link the ingame button to this code which would have the Unity player stuff for the new page (scene 2, replay stuff).

    I’ll probably also need a php script for the server:
    Code (CSharp):
    1. function makePage(){
    2.     var xmlhttp = new XMLHttpRequest();
    3.     xmlhttp.onreadystatechange = function(){
    4.     if(xmlhttp.readyState==4 && xmlhttp.status==200)
    5.         alert("webpage " + xmlhttp.responseText + " was successfully created!");
    6.     }
    7.     var content = "<html><head><meta charset=\"utf-8\" /> </head><body>new website<script>alert(\"test\")</script></body></html>";
    8.     xmlhttp.open("GET","makePage.php?content=" + content,true);
    9.     xmlhttp.send();
    10. }
    Then use Json to import everything???

    It’s a thought still hoping someone smarter than me can say hey dummy... you should just...
     
    Last edited: Jul 10, 2018
  3. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    Last edited: Jul 21, 2018