Thank you for visiting → Compete For Nothing.com ← If you find anything useful leave me a comment and share. Interested in Arduino, C#, Unity3D, Game Creation, VB.NET, learning and most important of all Sharing!.
Close Notification
Open Notification

Unity3D Pass Data to Online PHP using C# Coroutine

Unity3D Pass Data to Online PHP using C# Coroutine
GARD Pro Not Registered

Its easy to send data to a Online PHP script from your Unity3D game. For this tutorial we are going to use a “Coroutine”. which are extremely handy. So what we are going to do is this

  1. Send data from the game to a PHP script.
  2. Using PHP write that data to a file name sent in that data.
  3. Confirm the data was written.

Ok before we get started we need to create our PHP file, so on your hosting create a new PHP file called “save_player_data.php”

GARD Pro Not Registered

In “save_player_data.php” paste this

 

GARD Pro Not Registered

  Ok we got the PHP sorted out now upload it to your hosting and lets start with Unity3D.  

    1. Firstly create an “New -> Empty Game Object”  and call it SaveToPHP.

 

  • Create a new C# script and call it Senddata.

 

 

GARD Pro Not Registered
  • Paste this C# script into Senddate.cs.

 

 

   

 

Now save and Drag Senddate.cs and drop onto the Senddata object you created.

 

Now press Play in Unity and check your hosting (in the same directory and your PHP script) and you should have a new text file called PlayerName.txt, that contains PlayerName,SomeData,

 

Dogecoin
Donate Dogecoins: DGkJRWQCyBUeXbenYz18LRN9X67aora9nz Whats This?

6 Comments

  1. khizar · January 5, 2014 Reply

    hey. you named incorrectly . otherwise good effort thanx

  2. peter · November 17, 2014 Reply

    Hi,

    Thanks for posting this. I noticed that when I send the data string from unity to the php file, it works, but
    the characters in the string that follow a space are ignored.
    Example “hi bob” has a result of
    “hi” in the txt file created on the server.
    Can u suggest a fix or do I have to substitute space characters with “-” or something. Thx!

    Peter

    • warren · November 17, 2014 Reply

      Hey Peter,
      Yeah GET string on PHP looks for the a space to end the string so you would have to substitute the character. I’m glad you found it helpful :)

  3. Kyle · March 8, 2015 Reply

    Kewl This is really helpful! I was curious about what your thoughts were on the best way to retrieve that data back again? Could you give an example of using the player name as parameters and how to bring the data from text format from the server back into Unity? Thanks!

  4. Kyle · March 12, 2015 Reply

    No worries I figured it out

Leave a Reply to Unity3D Pass Data to Online PHP using C# Corout... Cancel reply