Search Unity

AutoPlay

Discussion in 'Editor & General Support' started by Deleted User, Jan 24, 2021.

  1. Deleted User

    Deleted User

    Guest

    I have made a website, and i put my unity game on there, but I have the problem where it automatically starts up and plays, is there any way to change that?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    If you used the default template for WebGL then your index.html page has JavaScript code that looks something like this on it:

    Code (CSharp):
    1.     <script>
    2.       var unityInstance = UnityLoader.instantiate("unityContainer", "Build/webgl.json", {onProgress: UnityProgress});
    3.     </script>
    So if you don't want to load the game up right away, I guess the way to do that would be to delay running code like that until something else happens on the page.
     
    Kurt-Dekker likes this.
  3. Deleted User

    Deleted User

    Guest

    ok, so is there i way i can make it like youtube vids, if i click on it, then that line of code runs?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Yes there is a way. The question you're asking is basically "How do I make an interactive website". I'm not a web developer myself, but you could go look up tutorials on how to make a button on a web page that runs JavaScript code. Once you can do that, it should be simple to just throw that JavaScript snippet from the Unity template into your button handler code.
     
  5. Deleted User

    Deleted User

    Guest

    ok thanks