- Home /
Animate text to smoothly transition between alignments
I have this menu, and when you go into sub-menus the main menu buttons move left to make space for the sub-menu. I have animated them so that they will move left, and switch text alignment from center to right. The problem is this is very sudden and happens over a single frame. I can't find a way to smoothly transition between text alignments. I'm using TextMeshPro. Any help?
Answer by Equ1l1brist · Aug 22, 2021 at 01:04 PM
DoTween will likely help you out for this http://dotween.demigiant.com/documentation.php. Check out the DoMoveX(Vector2) features on that link.
Also, it sounds like you may not have the length of your animation set correctly if it's happening over a single frame. But, I would scrap using Unity's Animation tool for simple movements like this and use DoTween instead.
Thanks, I'll check it out. The animation isn't actually just one frame, but it changed alignment from one frame to another. Sorry for the confusion!
Seems like I need the pro version to work with TextMeshPro.
Actually, you don't need the pro version if you're just moving the RectTransform that the TextMeshPro component is attached to. Those "Pro Only" TextMeshPro features are mostly for affecting the text itself.
Here's some code which I think achieves what you are looking for.
using DG.Tweening;
using UnityEngine;
public class RectTransformDotween : MonoBehaviour
{
RectTransform rectTransform;
float _target = 50f;
float _duration = 2.5f;
void Awake()
{
rectTransform= GetComponent<RectTransform>();
}
void Start()
{
rectTransform.DOAnchorPosX(_target, _duration);
}
}
Answer by hannabone3445 · Aug 22, 2021 at 08:17 PM
Hi! Hey! Perhaps you can find a solution to your problem here. There are also useful materials here that will help you develop in the future.
Your answer
Follow this Question
Related Questions
Can I make animations snap to a frame? 1 Answer
How do I place a left or right aligned Text where it would be if it was center aligned? 0 Answers
TextMeshPro meterial reverts to preefab default after collision 1 Answer
How to change text alpha with distance? 2 Answers
Text appearing letter by letter with animation on each letter? 0 Answers