0
我有一個場景,我必須從php獲取數據到我的Unity3d c#腳本中。當我調用www.text
時,我得到整個html頁面代碼。在PHP頁面中,我只是echo
的數據。www.Text返回整個html頁面不是數據
void Start() {
StartCoroutine(GetText());
}
IEnumerator GetText() {
UnityWebRequest www = new UnityWebRequest("http://192.18.23.1/php/Time.php");
www.downloadHandler = new DownloadHandlerBuffer();
yield return www.Send();
if(www.isError) {
Debug.Log(www.error);
}
else {
// Show results as text
//Debug.Log(www.downloadHandler.text);
// Or retrieve results as binary data
byte[] results = www.downloadHandler.data;
txt.text = "Success # " + www.downloadHandler.text;
}
}
編輯:
Time.php準則
<html>
<head>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="mqttws31.js" type="text/javascript"></script>
<script>
function myFunction(p1, p2) {
return p1 * p2;
};
var mqtt,payload;
var value = 10;
var reconnectTimeout = 2000;
function MQTTconnect() {
if (typeof path == "undefined") {
path = '/mqtt';
}
mqtt = new Paho.MQTT.Client(
'broker',
1883,
"/mqtt",
"a:" + "abcdef" + ":" + Date.now()
);
var options = {
timeout: 3,
useSSL: false,
cleanSession: true,
onSuccess: onConnect,
onFailure: function (message) {
$('#status').val("Connection failed: " + message.errorMessage + "Retrying");
setTimeout(MQTTconnect, reconnectTimeout);
}
};
mqtt.onConnectionLost = onConnectionLost;
mqtt.onMessageArrived = onMessageArrived;
//if (username != null) {
options.userName = 'username';
options.password = 'password';
//}
mqtt.connect(options);
}
function onConnect() {
// Connection succeeded; subscribe to our topic
mqtt.subscribe('iot-2/type/+/id/+/evt', {qos: 0});
$('#topic').val('iot-2/type/" + "+" + "/id/" + "+" + "/evt');
}
function onConnectionLost(response) {
setTimeout(MQTTconnect, reconnectTimeout);
$('#status').val("connection lost: " + responseObject.errorMessage + ". Reconnecting");
};
function onMessageArrived(message) {
var topic = message.destinationName;
payload = message.payloadString;
//document.getElementById("ws").value = payload;
};
</script>
</head>
<body>
<?php
echo '<script type="text/javascript">document.write(MQTTconnect());</script>';;
$ff = $_GET['payload'];
echo $ff;
?>
</body>
</html>
份額php文件,也許這將有助於http://wiki.unity3d.com/index.php?title=Server_Side_Highscores –
@MohammadFaizanKhan查看編輯部分.... – vikky
這是HTML文件,請參閱我以前分享你的鏈接。使單獨的PHP –