Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KoRnish7 · Apr 18 at 09:21 AM · c#rotationunityeditorrecttransform

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: alt text

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: alt text

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.

player2.png (12.0 kB)
player.png (6.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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: alt text

Can the rotation around parent object be somehow blocked as well?


player-3.png (3.2 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

180 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flip over an object (smooth transition) 3 Answers

Distribute terrain in zones 3 Answers

Scaling RectTransform to fit screen size in code 1 Answer

Multiple Cars not working 1 Answer

Can't stop camera from rotating on Z Axis 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges