Search Unity

Get Caret Position

Discussion in 'General Discussion' started by Zabse, Apr 14, 2021.

  1. Zabse

    Zabse

    Joined:
    Mar 30, 2021
    Posts:
    1
    I am quite new with unity and i have simple game, where the user can press a button and some text is placed inside an inputfield, this can be done manually by typing or using the buttons, but the issue i have is that i can only place the text created at the end of the inputfield, and not where the caret is currently positioned at.

    Code (CSharp):
    1. public void UpdateText(string text)
    2.     {
    3.         var position = InputFields.caretPosition;
    4.         InputFields.text = InputFields.text.Insert(position, text);
    5.     }