Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

[solved] Keep quad at end of visible text?

A topic by Scarlet String Studios created Mar 16, 2018 Views: 227 Replies: 3
Viewing posts 1 to 4
(1 edit)

First off, great job with this asset. I'm loving it so far, but I have one somewhat obscure use case in mind, and I'm wondering if it's achievable (or feasible).

Basically, I'm trying to simulate a text input field on a computer, where the cursor is always at the end of the current line while the person types. I can add a quad to the end of the line, but I'm not sure how to make the quad follow along with the text as it's being read out. I know about the <e2> tag, so I considered manually adding <q=cursor> each time the event is called, but I can't tell how much of the string has already been read, so I don't know where to insert the tag.

Developer (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.

Thank you! Will test this out shortly

Just checked and it's working perfectly. Thanks again!