Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by EchoStudio · Apr 19, 2012 at 01:54 AM · networkingwebplayerphp

PHP pass info to webplayer

Hello, I was just wondering if it was possible to generate a game ID in PHP.

I will try to explain it best I can.

Basically I was wondering if it was possible to set it up so that if the user visits: www.mydomain.com/MyGame/Game.php?id=1

Then it would set a variable in my webplayer stating that the user wants to join game with ID 1

Is this possible?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by IgnoranceIsBliss · Apr 19, 2012 at 03:57 AM

There was a method of getting the URL from the Application object, but when I tried it I found it didn't work very well.

My preferred method is to communicate between my Unity Web Player and the Javascript in my web page.

My Unity Application

 void Start()
 {
      Application.ExternalCall("GetID");
 }

 public void GiveID(string ID)
 {
      IDFromWebPage = ID;
 }

My Web Page

 function GetUnity() {
    if (typeof unityObject != "undefined") {
     return unityObject.getObjectById("unityPlayer");
    }
    return null;
 }
         
 function GetID()
 {
     //Set the ID...            
     var unity = GetUnity();
     unity.SendMessage("Main Camera","GiveID","<?php echo $_REQUEST['id']; ?>");
 }

So in this example, my Unity application uses Application.ExternalCall which calls a Javascript function named GetID in my web page.

That function then gets a handle to my Unity object and calls 'SendMessage' to call the GiveID function within my Unity project with the ID value I was interested in.

NOTE: In the example below, the Unity script is on the object named "Main Camera". You would need to alter your call to SendMessage to send the information to the appropriate Unity object.

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 IgnoranceIsBliss · Apr 19, 2012 at 04:00 AM 0
Share

I initiate the call from Unity rather than the web player because the Unity player takes some time to start up. Since Unity knows when you are going to need the data, it's easiest to start the exchange of data from the Unity side.

avatar image EchoStudio · Apr 19, 2012 at 04:24 AM 0
Share

Excellent, Works! Thank you!

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How should I go about creating an online multiplayer game that involves players trading game objects with eachother for real money? 2 Answers

Debugging Unity3D player crashes? 2 Answers

Using PHP to generate objects or list in Unity with C# 2 Answers

Unity networking tutorial? 6 Answers

Webplayer Facebook game- is a PHP script and a Unity script sufficient? 0 Answers


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