- Home /
Question by
aqeel25 · Mar 14, 2020 at 04:53 AM ·
uibuttoninputfield
Button Press Write Alphabet in textbox
I have created some buttons in Unity. When a button is clicked a function is called to write text on an InputText component. The function is following for example:
public void JButton() { textshowed.text = textshowed.text + "J"; }
But if I want to write a letter in between a line, the word is written at last of line. What should i do for the letter to written where the cursor/caret is?
I have also tried this but the button stops working
public InputField myInput;
int caretposition;
public void onJClick()
{
myInput.text = myInput.text.Insert(caretposition, "J");
//Debug.Log(myInput.caretPosition);
}
private void Update()
{
if (myInput.isFocused)
{
caretposition = myInput.caretPosition;
}
}
Comment