我在計算如何收集用戶輸入並將其保存以供以後使用時遇到問題。我找不到堆棧溢出的類似問題,並且我已經請求其他程序員尋求幫助,但無濟於事。Unity Csharp - 保存用戶輸入以備後用?
希望有人在這裏知道。在一個場景中,您可以輸入您選擇的任何輸入,並顯示您所寫的內容。這裏是我的代碼:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextInput : MonoBehaviour {
InputField input;
InputField.SubmitEvent se;
public Text output;
//public static string[] tasks = new string[]
//variable of array of strings so that you can save output text
void Start() {
input = gameObject.GetComponent<InputField>();
se = new InputField.SubmitEvent();
se.AddListener(SubmitInput);
input.onEndEdit = se;
}
public void SubmitInput(string arg0)
{
string currentText = output.text;
string newText = currentText + arg0 + " has been added to your schedule." + "\n";
output.text = newText;
input.text = "";
// save currentTezt for later use outline
//tasks.add(currentText)
/*Want to make each new text input equal a different amount of time
*/
}
//Need public array so that you can choose from the different strings --- you need the 'append' so that you can continue adding new tasks
}
我將如何延續的輸入,這樣我可以使用它,並在接下來的場景顯示。我很抱歉,如果答案非常簡單,我仍然在學習,我希望能夠變得更好。再次感謝你。