Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 SuperSparkplug · Dec 05, 2013 at 05:53 AM · rotationpositiontextmeshalignment

Anchor TextMesh position to objects.

Hello there.

My game features a player answering questions by going through a door, corresponding with their answer, which spawns a new room and a new question. There are 3 paths the player can take.

alt text

Right now, my problem is the positioning of the text for the questions and answers. As the game goes on, the positioning begins to misalign when its spawned in the instantiated room, especially if the player chooses either the left of right doors.

alt text

I'm not exactly sure how to align it properly. The code for this aspect of my game was written by a friend who is currently unavailable and while I understand the much of what the code he wrote does, I have no idea how to fix it. Here is the part of the code that handles the TextMeshes used for the Question and answers. Any ideas on how to correct this or how to properly anchor it to a separate object?

Note: This is only a minor detail in the grand scheme of things you are free to ignore, but is there anyway to make the text alignment within the text itself centred?

         int doorAnswer = 0;
         int doOnceOnly = 0;
                 
         foreach (var gameObj in FindObjectsOfType(typeof(GameObject)) as GameObject[]) {
             if (gameObj.name == "Body") {
     
                 objText.Add (new GameObject ("TextObject"));
                 
                 TextMesh textMesh = objText.Last ().AddComponent<TextMesh> ();
                 Font ArialFont = (Font)Resources.GetBuiltinResource (typeof(Font), "Arial.ttf");
                 textMesh.font = ArialFont;
                 //textMesh.text = "Hello World!";
                 
                 textMesh.text = Util.WordWrap (/*"A" + (doorAnswer + 1) + ") " +*/ content.answers[doorAnswer].text, 20);
                 textMesh.renderer.material = ArialFont.material;
                 textMesh.fontStyle = FontStyle.Bold;
                 
                 //Answers
                 GameObject door = gameObj;
                 textMesh.transform.rotation = door.transform.rotation;
                 textMesh.transform.position = new Vector3 (door.transform.position.x - 8, door.transform.position.y + 9, door.transform.position.z); //- cube.renderer.bounds.size.x / 2
                 textMesh.transform.Rotate (Vector3.up, -90, Space.Self);
                                  
                 
                 //0th is left door, 1th center, 2nd right
                 if (doOnceOnly == 1) {
                     //put question above center door
                     //Question
                     objText.Add (new GameObject ("TextObject"));
                     
                     TextMesh textMesh2 = objText.Last ().AddComponent<TextMesh> ();
                     textMesh2.font = ArialFont;
                     textMesh2.text = Util.WordWrap ("Q" + content.index + ") " + content.text, 70);
                     textMesh2.renderer.material = ArialFont.material;
                     textMesh2.fontSize = 18;
                     textMesh2.fontStyle = FontStyle.BoldAndItalic;
 
                     textMesh2.transform.rotation = door.transform.rotation;    
                     textMesh2.transform.position = new Vector3 (door.transform.position.x - 25, door.transform.position.y + 17, door.transform.position.z); //- cube.renderer.bounds.size.x / 2
                     textMesh2.transform.Rotate (Vector3.up, -90, Space.Self);
                     
                     doOnceOnly++;
                 } else {
                     doOnceOnly++;
                 }
                 
                 
 
                 doorAnswer++;
                 
                 
             }
         }
 
         
     }

screen shot 2013-12-05 at 12.14.55 am.png (380.2 kB)
screen shot 2013-12-05 at 12.15.42 am.png (334.4 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

0 Replies

· Add your reply
  • Sort: 

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

16 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

Related Questions

How to find the closest 4 verts/corners ( along with their orientation ) of a rectangular object in relationship with another object? 1 Answer

Positions to rotations of a regular GO 2 Answers

How can I make a First Person Character Controller a child of a moving platform without it affecting the rotation of the Character Controller. 1 Answer

Following another object's position/rotation like parent/child relationship? 4 Answers

How do I align my player transform to waypoints and without restricting Z Axis rotation? 2 Answers


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