- Home /
Locking RectTransform.rotation
Hi all.
I'm taking my first steps in Unity, and as my first project I'm fleshing out simple snowboard game I did as part of Unity2D Tutorial on Udemy.
My current problem is, I want to have a score counter above player's character:
So, I've attached empty GameObject as a child to my Player Game Object.
I've added TextMeshPro to it, which changed the Transform to RectTransform (wish it wouldn't do that, but I guess it can't be helped when textmeshis attached to the object?)
Now, the object with textmeshpro stays right above the player's character, when player is moving, which is great, however, when player rotate's his character, the score text also rotates:
How can I lock the rotation of the gameObject with TextMeshPro?
Ive tried getting the RectTransorm's rotation on awake, and then updating current RectTransform's rotation via Update, however it doesn't work, rotation still happens.
I've tried it for rotation, and localRotation, however both didn't work:
spinCounterObjectRect = spinCounterObject.GetComponent<RectTransform>();
iniRot = spinCounterObjectRect.localRotation;
iniRotLocal = spinCounterObjectRect.localRotation;
void Update()
{
spinCounterObjectRect.rotation = iniRot;
spinCounterObjectRect.localRotation = iniRotLocal;
}
I've tried putting new, zeroed out Quaternarion.Eulers in rotation and localRotation, but this also did nothing:
spinCounterObjectRect.rotation = Quaternion.Euler(0, 0, 0);
spinCounterObjectRect.localRotation = Quaternion.Euler(0, 0, 0);
I've also tried putting rotation and localRotation updates to LateUpdate, with no results.
Does anyone has any idea how to make it work? Thanks!
PS. Sorry for the formatting, editing this markdown here is a nightmare oO.
Answer by KoRnish7 · Apr 18 at 11:46 AM
I didn't notice it before, but the
spinCounterObjectRect.rotation = iniRot;
does change something.
The score no longer rotates around its asix, however it still rotates around the parent player gameobject:
Can the rotation around parent object be somehow blocked as well?
Your answer

Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Can't stop camera from rotating on Z Axis 1 Answer
Distribute terrain in zones 3 Answers
Scaling RectTransform to fit screen size in code 1 Answer
Multiple Cars not working 1 Answer