- Home /
LateUpdate not working properly for UI Text rotation
I am using the standard LateUpdate code to make text always face the Camera. Text correctly faces camera
void LateUpdate()
{
transform.LookAt(cameraToLookAt.transform);
transform.rotation = Quaternion.LookRotation(cameraToLookAt.transform.forward);
}
The text is under a Canvas that is attached to my Player GameObject. When I turn my player using the following code that is called from within a Coroutine, around half of the time the text glitches out for a frame and looks something like this before returning to normal: Not facing camera
public void TurnTowardsTarget(Vector3 position)
{
Vector3 direction = position - transform.position;
Quaternion rot = Quaternion.FromToRotation(Vector3.forward, direction);
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, rot.eulerAngles.y, transform.rotation.eulerAngles.z);
}
I don't understand why this is happening, and why it doesn't happen every time. I have no other LateUpdate methods in my project, so I don't see how this could be a script execution error unless Coroutines are known to mess with LateUpdate.
Your answer
Follow this Question
Related Questions
Updating ui not working in fixed update .But it works in update 1 Answer
TextMeshProUGUI Vertical Layout Group Overlaps Text 1 Answer
How to fix TextMeshPro breaking lines and escaping random characters? 0 Answers
Text UI not updating 2 Answers
Rotation problem while dynamically changing animations 2 Answers