Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

Vertically center text based on Vertical Limit?

A topic by GalaxyTrail created Aug 27, 2019 Views: 139 Replies: 2
Viewing posts 1 to 3
(1 edit)

I've been having good success with Super Text Mesh for our current game project and its speech bubbles/dialog boxes. One thing I'm wondering how to do, though, is center the vertical alignment of text based on its Vertical Limit. I thought about calculating the number of line breaks that are added when the text is displayed and then offsetting the Y position based on the results, but I would need a way to obtain both the number of line breaks that the Auto Wrap creates and the exact height of each line including the line spacing.

This is how the dialog box currently looks:

The dialog box is not part of a UI canvas.


Right now, that alignment is tied to the anchor point... so if you change the anchor to be Middle Left, Center, or Right, it should align in the way you want. I believe I made it like this because it reflects the behavior of Unity's standard text meshes. I hope that works for you!

Also, if you wanted to obtain the amount of line breaks, I believe the variable "linebreaks.Count", if made into a public variable would do it. Or hyphenedText.Split('\n').Count-1 could also be used! This would be without vertical limit modes though. I think changing the anchor point should be enough, though!

Just tried it out and it works! Thanks for the quick response!