Advertisemen
The simplest way to make a call to external server. This will be useful when you want to save user’s score or other information on your server when game starts, ends, user reaches the high score or any other situation you can think of.
Codes :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class postMessage : MonoBehaviour
{
public Text displayText;
// Use this for initialization
void Start ()
{
string url = "http://www.aarlangdi.com/unityPost.php";
WWWForm formDate = new WWWForm ();
formDate.AddField ("username", "aarlangdi");
formDate.AddField ("score", "100");
WWW www = new WWW (url, formDate);
StartCoroutine (request (www));
}
// Update is called once per frame
IEnumerator request (WWW www)
{
yield return www;
displayText.text = www.text;
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class postMessage : MonoBehaviour
{
public Text displayText;
// Use this for initialization
void Start ()
{
string url = "http://www.aarlangdi.com/unityPost.php";
WWWForm formDate = new WWWForm ();
formDate.AddField ("username", "aarlangdi");
formDate.AddField ("score", "100");
WWW www = new WWW (url, formDate);
StartCoroutine (request (www));
}
// Update is called once per frame
IEnumerator request (WWW www)
{
yield return www;
displayText.text = www.text;
}
}
Server code :
<?php echo "Username : ".$_POST["username"]."\n
Score : ".$_POST["score"];
?>
Advertisemen
Tidak ada komentar:
Posting Komentar