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 Capoymaster · May 09, 2016 at 04:55 PM · uigameobjectscreenviewport

UI elements following GameObjects (3d world)

After a deep research in this forum (found about 4 topics on this matter ) I am unable to make this running and i Don't figure out why ......... I'm very confused.

The ojective here is very simple : I have an Scene where 3d Objects will spawn , under certain circustances I want to Track the position of the object to the Screen or Viewport (not sure wich will fit) and render an UI element at the center of the object ( could be a text or an image , would like to play with this to mix 2d with 3d ).

Description of the Scene: For make things simpler i made a Prefab called "POINTER" , its a CANVAS with Space Overlay and Scale with Screen Size ( for multi resolutions purpose).. Then inside this Canvas I've got a simple text UI element All positions to 0 and anchors to 0,5 all. width and height are 30. ( i prooff tested to manually drag & drop this and It works and by default its placed in the midle of the screen ..... and if i tweak the transform of the text X and Y during play i can see it moving over the screen like im suposed to do by code, giving it the position of the gameobject to be over).

CODE:

  void Capoprueba(GameObject refobject)
     {
         Vector3 objt_position = refobject.transform.position;
         Vector3 viewport = Camera.main.WorldToScreenPoint(objt_position);
         viewport.y = -viewport.y;
        // Debug.Log(viewport);
         GameObject CanvasLabel = Resources.Load("POINTER") as GameObject;
        
         GameObject pl = Instantiate(CanvasLabel,viewport,Quaternion.identity) as GameObject;
        
 
     }

I did a bit testing about CanvasLabel.GetComponent().transform.localPosition = viewport; nothing seems to work :(_

Comment
Add comment · Show 1
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 tanoshimi · May 09, 2016 at 04:56 PM 0
Share

Why not just create the UI canvas in worldspace rather than as a screen overlay? That's kind of what it's for.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Flaring-Afro · May 09, 2016 at 06:03 PM

Create a world space canvas for each text/icon. Make the parent of each canvas the gameobject it moves with. Then, you will want to make a script for each canvas and in the update method, make its rotation match the camera's rotation, unless you want the text to be seen sideways depending on camera position.

Comment
Add comment · Show 1 · 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 Capoymaster · May 09, 2016 at 07:23 PM 0
Share

First of all thank you for replying; Yes I ' ve basically set the Canvas to Overlay to auto-adjust the UI - elements to the viewport whatever resolution is, and the behaviour was correct until now.

So giving this situation where more UI elements are co$$anonymous$$g I take your point as a viable solution; let's say I have to manually adjust the canvas Size ELements i Already have depending on the target device resolution and then will try to do the same for the upco$$anonymous$$g UI elements spawned.

I will come with the solution / or frustation under this way, Thank you !!

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

I can't get a button to register a touch and execute. 0 Answers

How to adjust the screen resolution? 0 Answers

Scroll View Null Reference error 0 Answers

Grid Layout Group leaking outside canvas. 1 Answer

How can I get a ray working with new UI system? 0 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