Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(2 edits)

Hey!


I was just thinking about this the other day, I might have a solution.

If this were an actual text input field, just adding the cursor to the end of the string would be fine, but this is just for animation purposes, so you might be able to do it like this:


using UnityEngine;
using System.Collections;
public class STMFakeCaret : MonoBehaviour {
    public SuperTextMesh stm; //the mesh to follow
    public Vector3 offset;
    void Update(){
        if(stm != null && //if there's a defined text mesh...
            stm.info.Count > 0 && //and it has textinfo to follow...
            stm.latestNumber > -1 && //and it's either drawing or done drawing...
            stm.hyphenedText[stm.latestNumber] != '\n'){ //ignore line breaks
            STMTextInfo myInfo = stm.info[stm.latestNumber]; //all info for this one character...
            //put the caret in the right place!
            transform.localPosition = myInfo.pos + myInfo.Advance(stm.characterSpacing, stm.quality) + offset;
        }
    }
}

If you put this on a gameobject that's the child of an object with your referenced Super Text Mesh on it, the object will follow the last drawn character! So I put this on a gameobject with a spriterenderer. You *will* have to modify Super Text Mesh's code just a bit to make this work, as the "info" list in STM is currently private, but I've changed it to be public to make this work.


Hope this solution works! I might add a custom event so you can call this function only when a new character is drawn, instead of putting it on Update.