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 Annig · May 20, 2015 at 11:04 AM · camerarotationpositiontextfollow

Having a 3D text appear in the middle of the screen without using GUI (C#)

Hi all,

For my game, I want to provide some text blocks with information. Because I'm going to use it with the Oculus Rift, I can't use GUI, so instead of using Canvas with Text children, I'm using 3D texts. For readability, I'm trying to get the text (when this is activated) to appear in the middle of the screen, no matter where the camera turns -- like you're using Screen Space - Overlay with a Canvas.

So far, I've found a script to attach to the 3D Text GameObject, which tracks the position of the camera (see code below). However, this isn't quite what I'm looking for as the text is still not stationary in the middle of the screen. I've tried using the same way of coding for tracking the camera rotation, but to no avail.

Is there anyone who could help me out? I'd greatly appreciate it!

 public class LookAtText : MonoBehaviour {
     public Camera cameraToLookAt;
         
     void Start() 
     {
             
         }
         
         
         
     void Update() 
             
     {
             
         Vector3 v = cameraToLookAt.transform.position - transform.position;
 
         v.x = v.z = 0.0f;
 
         transform.LookAt(cameraToLookAt.transform.position - v ); 
 
         //transform.Rotate(Camera.main.transform.rotation);
         transform.Rotate (0, 180, 0);
         }
         
     }
Comment
Add comment · Show 3
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
avatar image Annig · May 20, 2015 at 01:34 PM 0
Share

Worked like a charm, thank you so much! I can't believe I was trying to script it when the solution was so straightforward..

avatar image malkere · May 20, 2015 at 01:40 PM 0
Share

should answer as answers not comments. thread looks forever unanswered =O

avatar image KdRWaylander · May 20, 2015 at 01:46 PM 1
Share

@malkere Indeed, but since I wasn't sure it was what he was looking for i put it as a comment until he tests it :) Now it's an answer and people now that the question is answered !

@Annig Unity is made to be simple, sometimes the easiest way is the best :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by KdRWaylander · May 20, 2015 at 11:13 AM

Hey, what you can do is put the text as a child of one of the cameras (left or right), set its position to (0,0,0) and then use local position to put the text as far as you want from the camera. In this way, it will always follow the movement of the camera ... look at this tutorial, you could adapt your way to it: https://www.youtube.com/watch?v=LLKYbwNnKDg

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
avatar image
0

Answer by Owen-Reynolds · May 20, 2015 at 01:49 PM

Looks like you're just starting with positioning and rotating objects. Putting something in front of the camera, or facing the camera, is no different than putting something in front/facing the player, or a cube... . Reading through the basics should make various solution to this obvious.

As kdrwl writes, an easy way is to use local position. In the Editor, child an object to something and play with position (which automatically counts as localPosition, even though it doesn't say) to get a feel for it (same with rotation.) In code: myText.parent=someCamera; myText.localPosition=new Vector3(0,0,10);. Since we all know Z is forward, this puts you 10 units along the camera's blue(Z) arrow. Then myText.LookAt(someCamera); aims directly at it.

Can also use world positioning, involving someCamera.forward*10;. It appears your last line is part of the trick "face the exact way as something, then spin around to face it." Whole thing is: myText.rotation=someCamera.rotation; myText.Rotate(0,180.0);. But don't mix methods. There are a few ways to do it, none of them very long, but it's easy to use 1/2 of method A and 1/2 of method B, and get junk.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

Create camera transition from one point to top of object 1 Answer

Runescape Camera Rotation? 0 Answers

Camera Follow Mouse 2 Answers

How do I let a camera follow on one axis? 3 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