Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 bstout · Dec 06, 2016 at 04:33 AM · camerainstantiateaim

aim 3D text at camera

I am trying to aim instantiated 3d Text at the camera. It all compiles but the text won't aim. Here's the code:

 Instantiate(textMesh, pos, textMesh.transform.rotation );
         GameObject cam = GameObject.FindWithTag("MainCamera");
         Debug.Log (cam);
         target = cam.transform;
         Transform textTransform = textMesh.transform ;
         Debug.Log (textTransform);
         textTransform.LookAt(target);

Thanks for any solutions.

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
Best Answer

Answer by HarshadK · Dec 06, 2016 at 05:20 AM

You need to set the LookAt for the instantiated object. You are doing it for the textMesh currently. It should be:

 GameObject instantiatedTextMesh = (GameObject) Instantiate(textMesh, pos, textMesh.transform.rotation );
  GameObject cam = GameObject.FindWithTag("MainCamera");
  Debug.Log (cam);
  target = cam.transform;
  Transform textTransform = instantiatedTextMesh.transform ;
  Debug.Log (textTransform);
  textTransform.LookAt(target);
Comment
Add comment · Show 4 · 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 bstout · Dec 06, 2016 at 03:46 PM 0
Share

it wouldn't take the GameObject casting because, the Text$$anonymous$$esh is not a GameObject. So I instantiated it as a Text$$anonymous$$esh and then it all worked. Wooot !

         Text$$anonymous$$esh  instantiatedText$$anonymous$$esh = (Text$$anonymous$$esh) Instantiate(text$$anonymous$$esh, pos, text$$anonymous$$esh.transform.rotation );
         GameObject cam = GameObject.FindWithTag("$$anonymous$$ainCamera");
         target = cam.transform;
         Transform textTransform = instantiatedText$$anonymous$$esh.transform;
         textTransform.LookAt(target);

avatar image bstout · Dec 06, 2016 at 08:02 PM 0
Share

thanks Harshad. This is a step forward. The text$$anonymous$$esh now instantiates facing the camera, but then the game freezes and gives this message "InvalidCastException: Cannot cast from source type to destination type." So I guess it doesn't like me telling the text$$anonymous$$esh that it is a GameObect.

avatar image HarshadK bstout · Dec 07, 2016 at 09:49 AM 0
Share

On which line is it exactly throwing that exception?

avatar image bstout HarshadK · Dec 07, 2016 at 12:59 PM 0
Share

the error occurs on GameObject instantiatedText$$anonymous$$esh = (GameObject) Instantiate(text$$anonymous$$esh, pos, text$$anonymous$$esh.transform.rotation );

changing GameObject to Text$$anonymous$$esh works. for whatever reason unity can't recast 3d text as a GameObject.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Checking if object intersects? 1 Answer

Make camera follow an instantiated object 1 Answer

main camera destroying in editor but not in android 1 Answer

Spawning problems with cameras 1 Answer

Gun is shooting based on movement not camera rotation? 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