• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by Joshua Mitchell · Mar 05, 2010 at 03:26 PM · variableurl

How can you send variables to unity3d from the url?

Need to send variables in to unity3d from url.

Example: www.domain.com?varname=4

Then have access to varname in unity3d like a global variable.

thanks,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bernardfrancois · Jan 01, 2014 at 08:37 AM

Application.srcValue and Application.absoluteURL doesn't work (at least in Unity 4.3), as these values do not contain anything past the ".unity" bit in the URL.

I needed to read URL parameters myself, so I did some more work to find the solution and created a RequestParameters.cs class that does it for you (just add it to a gameObject and call the string GetValue(string key) function: http://www.previewlabs.com/reading-url-parmeters-from-web-player-builds

This uses Application.ExternalEval to run browser-side JavaScript, and pass the document.location.search value to Unity code through SendMessage().

It's explained a bit more in detail in the article containing the RequestParameters.cs class.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ArunRaj · Aug 17, 2011 at 06:25 AM

thank it helped me a lot :)

when passing two arguments , follow this

and follow the same steps !!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by alph · Apr 13, 2011 at 11:11 AM

I'd like to add my 5 cent to this, as I couldn't find any relevant example code to do exactly what I wanted to do.

Using Unity3D v.3.3 and building for webplayer, unity will make a ready WebPlayer.html file for you that embed your .unity file and everything works off the bat. To get url parameters from this setup using PHP do this:

  • copy WebPlayer.html to WebPlayer.php and open in your favorite editor
  • add this line to the very top of the php file:

<? $arg = $_GET["arg"] ? "?" . $_GET["arg"] : null; ?>

  • about line 15/16 find this code:

unityObject.embedUnity("unityPlayer", "WebPlayer.unity3d", 680, 600);

  • replace "WebPlayer.unity3d" with this:

"WebPlayer.unity3d<? echo $arg ?>"

  • in the url, call your game with something like this: http://myServer.com/pathToGame/WebPlayer.php?arg=myArg1,myArg2,myArg3...

  • now in unity:

string raw = Application.srcValue;
string[] tmp = raw.Split('?');
string myArguments = tmp[1]; // will give you "myArg1,myArg2,myArg3..."
// ..further parse myArgument as you like

This can probably be done in different ways, don't hesitate to comment some improvements..

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ABerlemont · Apr 21, 2015 at 03:38 PM 0
Share

Great "workaround" Using u5 and Application.srcValue stops at the unity3d file path. I'm using Application.absolutePath ins$$anonymous$$d.

avatar image Ricna · Jan 12, 2016 at 06:24 PM 0
Share

I had used this same way for my applications, but now I need to build the same app for WebGL. I'm trying to find a way without success until now. The application don't receive the params from URL but from a query in databases using the PHP. You know how to get the parameters in this case? Thanks!

avatar image
-5

Answer by Minato Namikaze · Mar 12, 2010 at 07:39 AM

Re-post, sorry about that.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SrBilyon · May 29, 2011 at 04:40 AM 0
Share

It all good bro. :)

avatar image
-2

Answer by Minato Namikaze · Mar 06, 2010 at 07:45 AM

Importing assets is simply done as dragging and dropping them onto the Unity window.

EDIT: Sorry, I didn't realize you meant receiving variables from websites. Disregard my post.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Motionreactor · Mar 09, 2010 at 05:25 AM 0
Share

You missed the point of the question. The question refers to runtime data acquisition, not editor asset importing.

  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

AddListener with argument on multiple Buttons 1 Answer

y value doesn't update 1 Answer

Public Variables in MonoBehaviour Scripts reset to "None" in Playmode 0 Answers

Reading reference variable alters said reference variable 1 Answer

Animation Curve to Float variable? help! 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges