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 DaveA · Mar 26, 2011 at 12:36 AM · 3dhudpointerguilayer

What's the best way to draw a 'pointer' from GUI layer to 3d scene?

At runtime (not Editor), and barring GL or some add-on, what's the best way to draw, say, a triangle that has two vertices anchored on a GUI element, and one vertex in the 3d scene?

I get the GUI element's screen rect and convert that to world coords (using Camera.main). They all look reasonable. Then I try to create a mesh consisting of 2 triangles (back to back) using those 3 coordinates. MeshRenderer and everything, but I'm not seeing anything in the scene.

Am I missing some 2D drawing class I should be using instead (convert the 3D point to screen space and draw my pointer in the GUI layer?)

Is there a better way? BTW: It doens't have to be a triangle, just something nice to tie the 2D to 3D.

Comment
Add comment · Show 2
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 Peter G · Mar 26, 2011 at 01:27 AM 0
Share

So you want something like an objective arrow?

avatar image DaveA · Mar 26, 2011 at 02:15 AM 0
Share

I suppose. Info on the HUD that points to (and tracks) object(s) in the 3D scene.

3 Replies

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

Answer by DaveA · Mar 31, 2011 at 11:29 PM

Well it took some futzing. I'm this close (holding index finger very near thumb) away from selling this on the Asset Store, but here's the nugget anyway, I'll let you fill in the details:

in LateUpdate():

  var p0 : Vector3 = targetTransform.position;
  var p1 : Vector3 = Camera.main.ScreenToWorldPoint (Vector3 (left, top, Camera.main.nearClipPlane));
  var p2 : Vector3 = Camera.main.ScreenToWorldPoint (Vector3 (left+20, top, Camera.main.nearClipPlane));
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 Zib Redlektab · Mar 26, 2011 at 02:07 AM

I can't speak from experience, but you probably want Gizmos. http://unity3d.com/support/documentation/ScriptReference/Gizmos.html

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 DaveA · Mar 26, 2011 at 02:14 AM 0
Share

Hmm. I thought those were Editor-only, but maybe not?

avatar image Jesse Anders · Mar 26, 2011 at 05:49 AM 0
Share

I believe they are editor-only.

avatar image
0

Answer by Owen-Reynolds · Mar 26, 2011 at 07:34 AM

Are you seeing the triangle in the Inspector for the Mesh during a run?

One thing that bit me: setting mesh.vertices = new Vector3[3]; mesh.Vertices[0]=...' said it gave me a 3-vert, 2 face triangle but didn't really. You have to set mesh.Vertices to a complete, pre-existing array (which is how the docs do it.)

If you set your corners to the actual world coords, you'll have to set the Transform to (0,0,0). Problem is, Unity now thinks your Mesh is at (0,0,0) and won't draw if that's behind you, too far away... . If you run towards the (0,0,0) corner and it pops up, that was the problem.

I would probably set the Transform to your first corner, so the Mesh counts as being in view, then set the other corners to (v2-v1) and (v3-v1). Actually, before that I'd draw a 0/1 square set 20ish in front of the camera, as a test.

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 DaveA · Mar 26, 2011 at 08:35 AM 0
Share

Sounds very promising, will try ($$anonymous$$onday), Thanks

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

No one has followed this question yet.

Related Questions

3d Object in GUI Layer 2 Answers

Object to always appear same size on HUD 3 Answers

How can i make changes like in example? 0 Answers

HUD animation with game in background 0 Answers

I want to make a pointer with a 2d image that will take the position of rendered 3d model's mesh and will move with my mouse position. 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