• 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
2
Question by Faskoona · Oct 11, 2010 at 04:43 PM · webplayerdatabasemysqlphp

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

Hello,

I have searched up and down for some information on using PHP to generate content in Unity. Here is what I am trying to do:

The goal is to create an interface in the webplayer generated by entries in a php document.

Example:

Unity contacts php. The php file tells Unity that there are 2 entries. Each entry is for a separate webplayer game. Unity retrieves 2 URLs per entry (one for the webplayer and one for an image location). So now Unity has information that there are 2 games on my server. Unity uses this info to instantiate a prefab (a simple pane) that will act as a button. Once the button is created, the PNG image is applied as a render texture, and the webplayer url is attached in the button script. The newly created button can now be clicked and it will load the new webplayer game.

In this manner a menu list can be dynamically generated based on how many entries there are in the php file. (hopefully all this makes sense)

Since I am a beginner in PHP and C# I am looking for a basic example of the php and the C# script to get me started.

Thank you.

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

2 Replies

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

Answer by duck · Oct 11, 2010 at 10:09 PM

First of all read this answer to find out about how to communicate with web scripts in Unity in general:

How can I send and receive data to and from a URL, i.e. server side scripts, web services, etc?

You'll want to use the .data variable of the completed WWW object to read the file containing the URLS.

Once you have this data as a string, you'll want to split it up by whatever delimiters you have chosen. Perhaps they're separated by a certain character, with each pair separated by a newline. Or perhaps you've chosen a more advanced data format like JSON or XML.

Assuming the former, you can parse your individual items of data out using something like the method described in this answer (except instead of using a TextAsset, the text comes from the value returned by your WWW call):

putting a large amount of data into structures

Next you'll want to load the texture, which you can do using exactly the same method that you used to load the URL strings, except you need to read out the .texture variable instead of the .data variable on the WWW objecct once the call is complete.

(Referring to this as a RenderTexture is incorrect. A RenderTexture is a texture generated from the view of an in-game camera, and is often used to create realtime reflections).

Finally you might want to use this texture on a button, in a list of GUI buttons - a method do draw a list of textures like this is described in this answer which uses a for loop to draw an array of toggles.

In that example, it uses the number of children of the gameobject as the array of items, so you'd want to substitute that for your list of games.

Also you'll want to use buttons instead of toggle items for the actual GUI elements for each item.

Hope this is enough to get you on your way!

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 Faskoona · Oct 12, 2010 at 04:21 PM 0
Share

Thanks so much for the help! I'm still working on setting this up, but so far so good.

avatar image
0

Answer by furic · Dec 10, 2014 at 06:49 AM

If you use GameAnalytics like me, just use JSON created in PHP and phase them in C#

PHP code:

 $output['coins'] = $coinsGain;
 $output['gems'] = $gemsGain;
 $output['exp'] = $expGain;
 $output['status'] = 'success';
 $output['checksum'] = md5($coinsGain . '|' . $gemsGain . '|' . $realHash . '|' . $secretKey);
 echo json_encode($output);

PHP output:

 {"coins":18,"gems":10,"exp":10,"status":"success","checksum":"e147ad20659b7462499b29dee9dc2bb6"}

C# code:

 WWW post = new WWW (postURL + someInput);
 yield return post;
 Hashtable returnParam = (Hashtable)GA_MiniJSON.JsonDecode (post.text);

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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Web Player and database 1 Answer

Why i keep getting this message : Wrong response ? 0 Answers

How to get Variable from Php Script? 0 Answers

unity3d connect to php or coldfusion for database information 2 Answers

WebHosting with phpMyAdmin PHP 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges