Я пытаюсь прочитать данные из базы данных mysql, размещенной на mamp, для отображения информации об игроках в сцене единства.Я могу читать и писать в базу данных, но я вообще не знаю, как отобразить информацию в единстве.Я читал, что вы можете использовать JSON для форматирования данных, а затем отобразить их в единстве, но я не знаю, с чего начать.Любая помощь будет принята с благодарностью.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GetPasswords : MonoBehaviour
{
string URL = "http://localhost:8888/sqlconnect/usergetpasswords.php";
public string[] usersData;
public void RetrievePasswords()
{
StartCoroutine(GetPasswords());
}
IEnumerator DisplayPasswords()
{
WWWForm form = new WWWForm();
form.AddField("email", DBManager.email);
WWW www = new WWW(URL);
yield return www;
string usersDataString = www.text;
usersData = usersDataString.Split(';');
Debug.Log(usersData);
}
// Update is called once per frame
void Start()
{
RetrievePasswords();
}
}
php script
<?php
//place the relative position of the database such as https://www.000webhost.com/cpanel-login?from=panel.
$con = mysqli_connect('localhost', 'root', 'root', 'unityaccess'); //replace root, root with your server username and password.
//Check that connection happened.
if (mysqli_connect_error())
{
//echo similar to debug, the message will populate the www.
echo "1: Connection failed"; //error code #1 = connection failed
exit();
}
$email = $_POST["email"];
$sql = "SELECT email, account1, password1 FROM players WHERE email='" .$email . "';";
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo ("email: ".$row['email']."|account1: ".$row['account1']."|password1: ".$row['password1'].";");
}
}
?>