• 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 Stealthygolem · Nov 02, 2014 at 10:31 PM · c#camerainstantiateguitextworldtoscreenpoint

C# 2d Instantiate GUIText and lock it to position on map, not to follow camera.

Hello. I am having a really hard time trying to work with GUIText instantiation. I want the instantiate to be placed correctly just like any other GameObject instantiation, but it works too mysteriously for me. I have atleast managed to make it spawned at the correct position initially, but it still happens to follow the camera when any other movement of the camera is made. So, I want t$$anonymous$$s to not happen. I want t$$anonymous$$s to have its own fixed position on the game map.

Relevant code:

  public GameObject textGUI;
 
         void OnTriggerStay2D(Collider2D col) {
         if(col.gameObject.tag == "Food") {
             //Add to current health
             curhp += 5;
             FoodPoint();
             audio.PlayOneShot(munchFood);
             Destroy (col.gameObject);
         }
     }
 
     void FoodPoint() {
         Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
 
         pos.x = pos.x /Screen.width;
         pos.y = pos.y /Screen.height;
 
         GUIText obj = GUIText.Instantiate(textGUI,pos, Quaternion.identity) as GUIText;

There is more stuff that is incorrect at the moment, like passing on new information to the textGui. It is none of my concern at t$$anonymous$$s moment. I just want to know how I can instantiate on the game map, not the camera. Thank you for any help.

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

Answer by Kiwasi · Nov 02, 2014 at 11:24 PM

GUIText are positioned on the screen. They don't pay any attention to cameras or world space or the like.

Two options to solve

  • Use a TextMesh. T$$anonymous$$s is a 3D component that can be positioned in world space

  • Upgrade to Unity 4.6 and use a world space canvas.

Comment
Add comment · Show 2 · 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 Stealthygolem · Nov 02, 2014 at 11:38 PM 0
Share
avatar image Kiwasi · Nov 03, 2014 at 02:01 AM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Credits Camera Script 3 Answers

GUIText Instantiation and Update the Instantiated Text. C# 1 Answer

Spawn Ground right next to current ground 1 Answer

Incorrect X position from worldToScreen method 0 Answers

C#, How do I make the GUIText Show up if Instantiate from a prefab. 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