我有这个脚本
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HSController : MonoBehaviour
{
public string addScoreURL = "IP ADDRESS/adduser.php"; //be sure to add a ? to your url
void Start()
{
//string scores = nameField.text;
StartCoroutine (PostScores (scores));
}
// remember to use StartCoroutine when calling this function!
IEnumerator PostScores(string name)//string name)
{
//This connects to a server side php script that will add the name and score to a MySQL DB.
// Supply it with a string representing the players name and the players score.
// first we create a new WWWForm, that means a "post" command goes out to our database (for futher information just google "post" and "get" commands for html/php
WWWForm form = new WWWForm();
// with this line we will give a new name and save our score into that name
// those "" indicate a string and attach the score after the comma to it
form.AddField("NAME", name);
// the next line will start our php file that saves the Score and attaches the saved values from the "form" to it
// For this tutorial I've used a new variable "db_url" that stores the path
WWW webRequest = new WWW(addScoreURL, form);
// with this line we'll wait until we get an info back
yield return webRequest;
}
}
但我想获取他们输入到inputField的用户名。但我无法弄明白。我在场景中有输入字段和提交按钮,但是如何将它们连接到我的脚本并将其传递给它。
由于
答案 0 :(得分:0)
第一。删除您的PHP标记。我知道这与PHP有关。因为它是一个post请求但不是Unity3D。开发人员可能会浪费时间查看您的问题。
// Make this public so it will be available in the inspector. Check what game object is attached to
// Drag the Text into the MyInputField.
public Text MyInputField;
form.AddField(MyInputField.text, myinput);
// If you don't like Dragging it from the Inspector or don't want your Myinputfield to be public
// You can use GameObject.Find("MYinputFieldName").GetComponent<Text>();
// GameObject.Find is Slow and should be avoided if you're Performance concious.