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

How to load different builds from the same Index.html

Discussion in 'Web' started by danielesuppo, Jul 31, 2019.

  1. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Hello,
    unfortunately I'm really a newbye of html, I have a webgl game that should run in some way on desktop, in another way on tablet and in a third way on smartphones.
    So I've created 3 different builds.
    In my Index.html I can detect the device (desktop/tablet or smartphone) through javascript, but I don't know how to redirect the build that should be loaded on the base of the device detected.

    I have idea that the main loading job, in Index.html, is made by:
    <script src="Build/UnityLoader.js"></script>
    and
    var gameInstance = UnityLoader.instantiate("gameContainer", "Build/myBuild.json", {
    onProgress: UnityProgress,
    compatibilityCheck:CheckCompatibility,
    Module: {
    //TOTAL_MEMORY: 268435456,
    onRuntimeInitialized:RuntimeInitialized,
    },
    });

    I think that I should change the path of these 2 files, for example:
    if (deviceDetected == "Tablet")
    {
    <script src="BuildForTablet/UnityLoader.js"></script>
    var gameInstance = UnityLoader.instantiate("gameContainer", "BuildForTablet/myBuild.json", {.... ....
    }
    else if (deviceDetected == "Smartphone")
    {
    <script src="BuildForSmartphone/UnityLoader.js"></script>
    var gameInstance = UnityLoader.instantiate("gameContainer", "BuildForSmartphone/myBuild.json", {.... ....
    }

    but I really don't think that on the Index.html it could work like that.
    Does anyone could give me any advise how to load different builds on the base of a condition?

    Many thanks!