Header Ads

Locate last word And print number of lines of text ui in unity

- Check the number of lines of text you display
-get the last position of the text

SCRIPT:
getlines:

 public TextMeshProUGUI text;
   void Update()
   {
        showline();
   }

    private void showline()
    {
        text.ForceMeshUpdate();
        for(int i = 0; i<text.textInfo.lineCount;i++)
        {
            int StartIndex = text.textInfo.lineInfo[i].firstCharacterIndex;
            int endIndex = (i == text.textInfo.lineCount -1 ) ? text.text.Length : text.textInfo.lineInfo[i+1].firstCharacterIndex;
            int Length = endIndex - StartIndex;
            Debug.Log(text.text.Substring(StartIndex,Length));
        }
    }

lastword:

 public TextMeshProUGUI text;
   public float xx;
   public float yy;
   void Update()
   {
        Vector3 Bleft = text.textInfo.characterInfo[text.textInfo.characterCount -1].bottomLeft;
        Vector3 WorlBleft = text.transform.TransformPoint(Bleft);
        Vector3 image = transform.parent.InverseTransformPoint(WorlBleft);
        transform.localPosition = new Vector3(image.x-xx,image.y-yy,0);
   }


Video

No comments

Powered by Blogger.