1

All I want to do is get the variable newtext back to just below main section so that I can continue to use it, but whatever I try I can't. I'm very new to c# and unity, I'm trying to do a old school adventure like the ones in the 80's I've written a script under this to break the input newtext into verb and noun (which works), just can't get the string newtext back to allow me to do this, any help with this would be greatly appreciated.

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();
    }





}
Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
  • I don't understand the question, do you want to call a function when the user ends editing your inputfield? – Juan Bayona Beriso Feb 10 '17 at 13:58
  • what I want is when the user finishes entering the string in the function how do I get the variable back so I can use it with other instructions i.e. if statement below the line input.onEndEdir.AddListener(SubmitInput); – Steve Potts Feb 10 '17 at 15:31

1 Answers1

1

If you want to call a function with the text of the inputField when the user submits the input you can use 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();
}