Hey guys,
How would clear all the text?
I don’t really know how to do it
public Canvas myCanvas;
public Text myText;
// Creates varibles to view more text
private string display = "";
private bool engagedText;
List<string> textEvents;
// Creates varibles inorder to reconised input commands
public InputField inputfield;
// Creates a Command string that holds commands
private Dictionary<string, System.Action<string,string>> commands;
protected void Awake()
{
//Holds the command string and points them to their methods and functions
// Listen when the inputfield is validated
commands = new Dictionary<string, System.Action<string,string>>();
commands.Add( "help", onHelpTyped );
inputfield.onEndEdit.AddListener( OnEndEdit );
}
void Start () {
textEvents = new List<string>();
textEvents.Add ("Welcome to my App");
textEvents.Add ("Your currently offline (console), login to go online");
textEvents.Add ("Type help for help");
engagedText = true;
}
void Update () {
if(engagedText)
{
AddText();
engagedText = false;
}
}
private void OnEndEdit( string input )
{
// Only consider onEndEdit if Submit (Enter/return) key being press
if ( !Input.GetButtonDown( "Submit" ) )
return;
bool commandFound = false;
// If the command is entered,it finds the correct command
foreach ( var item in commands )
{
if ( item.Key.ToLower().StartsWith( input.ToLower() ) )
{
commandFound = true;
item.Value( item.Key, input );
break;
}
}
// If command is not founded, perform this task & clear the InputField
if ( !commandFound )
textEvents.Add ("Command not founded");
engagedText = true;
inputfield.text = "";
}
// Help function
private void onHelpTyped( string command, string input )
{
textEvents.Add ("hi");
textEvents.Add("hello");
textEvents.Add("mate");
engagedText = true;
}
// Add the new text while keeping the old text.
void AddText()
{
display = "";
foreach(string msg in textEvents)
{
display = display.ToString () + msg.ToString() + "
";
}
myText.text = display;
}
}