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

Passing web parameters into Unity

Discussion in 'Scripting' started by mlewis, Feb 27, 2010.

  1. mlewis

    mlewis

    Joined:
    Jun 5, 2009
    Posts:
    13
    Is there a way to pass parameters from a web site into a unity web based application ?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  3. mlewis

    mlewis

    Joined:
    Jun 5, 2009
    Posts:
    13
    Thanks Eric !!
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Or! You might also consider adding parameters on to the src URL for your *.unity3d file, then parsing those within your game. For example, instead of this:

    src=myFile.unity3d

    Use this:

    src=myFile.unity3d?foo=hello

    Then inside of your game check Application.srcValue and strip/parse everything after the question mark. Note that this may trigger fresh downloads of your *.unity3d file as unique data means a unique URL which means a fresh download, but it might work in some cases so consider it a possibility.


    This is a good prompt for me, I have a great example already in place of how you can use "deep linking" to by default go to a specific level within Unity. For example, go here:

    http://files.unity3d.com/tom/DeepLinking/

    That loads Level 0, just a simple menu, no characters. Press the buttons though, notice how doing that appends a #<name> to the end of the URL? Bookmark one of those URLs, or just load this instead:

    http://files.unity3d.com/tom/DeepLinking/#Penelope

    Now notice that it loads that level by default! Two way browser communication at work, passing of parameters at work, etc. I gotta get a blog post up on that ASAP. It uses the APIs discussed at the URL Eric provided above, not my second suggestion.
     
  5. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    i was looking how to do this, it is kind of confusing i must add, but that is probably because i dont understand it :)
    i was looking into how to pass some parametars to the unity so that i can start player with something like this:

    www.site.com/unitytest.html?param1=something&param2=something

    something similiar to the link to the location in the google maps.
    so when the player is loaded it can zoom certain location...

    there are numerous ways to do it in the forums, i am looking the easiest one that will not involve changing html that unity2.6 produced
    (at least to much, because it might brake some other things)

    thanks to everybody that is willing to look into this and point me in the right direction!

    thank you
     
  6. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    @HiggyB it seems that your example does not work in google chrome, it does not load character
     
  7. bernardfrancois

    bernardfrancois

    Joined:
    Oct 29, 2009
    Posts:
    373
    I've been looking into this myself and found no immediately working solution on the forums or through google, so created something myself.

    The RequestParameters class, made available for anyone to use on my company's blog, does the trick. It's my little New Year's present to the community :)
    previewlabs.com/reading-url-parmeters-from-web-player-builds

    Simply add it to any GameObject in your scene, and call the string GetValue(string key) method.

    [edit]
    Note that Application.srcValue and Application.absoluteURL don't contain anything past the ".unity" bit in the file name - just tried it in Unity 4.3 in a web player build.

    @HiggyB: the deep linking examples you created don't seem to work any more with current the Web Player plugin. Did you end up writing your blog post about this?
    [/edit]
     
    Last edited: Jan 1, 2014