C# 使用InputField的登录脚本
我有这个剧本C# 使用InputField的登录脚本,c#,unity3d,C#,Unity3d,我有这个剧本 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() { //strin
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中输入的用户名。但我想不出来。我在场景中有输入字段和提交按钮,但如何将它们连接到脚本并将其传递给脚本
谢谢你。删除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.
//将其公开,以便在inspector中可用。检查附加到哪个游戏对象
//将文本拖到MyInputField中。
公共文本MyInputField;
AddField(MyInputField.text,myinput);
//如果您不喜欢从检查器中拖动它,或者不希望Myinputfield是公共的
//您可以使用GameObject.Find(“MYinputFieldName”).GetComponent();
//GameObject.Find速度很慢,如果您对性能要求很高,应该避免使用。