2017-02-10 69 views
1

我想要做的就是將變量newtext返回到主要部分下方,以便我可以繼續使用它,但無論我嘗試什麼,我都不能。我對C#和團結非常陌生,我試圖做一個像80年代那樣的老式冒險,我在這之下寫了一個腳本,用於將輸入的新文本分解爲動詞和名詞(它有效),只是可以不要讓字符串newtext回來讓我這樣做,任何幫助,這將不勝感激。文本輸入進一步使用

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 


public class Textinput : MonoBehaviour { 
    // declare variables below 


    InputField input; 
    InputField.SubmitEvent se; 
    public Text output; 


    // declare variables above 
    void Start() { 

     input = gameObject.GetComponent<InputField>(); 
     se = new InputField.SubmitEvent(); 
     se .AddListener(SubmitInput); 
     input.onEndEdit = se; 


     //want varable script to come back here to use ie "newtext" to use after this point 

       // **split word script here ** 

    } 


    // my voids below 
    private void SubmitInput(string arg0) 

    { 
     string currentText = output.text; 
     string newText = arg0; 
     output.text = newText; 
     input.text = ""; 
     input.ActivateInputField(); 
    } 





} 
+0

我不明白的問題,你想叫當用戶結束編輯你的輸入字段時的功能? –

+0

我想要的是,當用戶在函數中輸入字符串完成後,我如何獲取變量,以便我可以將其與其他指令一起使用,例如,如果語句在行下面input.onEndEdir.AddListener(SubmitInput); –

回答

1

如果您想在用戶提交輸入要撥打與inputField的文本功能,您可以使用onEndEdit

void Start() { 
    input = gameObject.GetComponent<InputField>(); 
    input.onEndEdit.AddListener(SubmitInput); 
} 

private void SubmitInput(string arg0) 
{ 
    string currentText = output.text; 
    string newText = arg0; 
    output.text = newText; 
    input.text = ""; 
    input.ActivateInputField(); 
}