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
2
Question by pretender · Oct 23, 2010 at 05:51 PM · guirenderlineopenglscreenspace

how to render line between gui element and mouse position

i am trying to use OpenGL to render line between gui element and mouse position.

i am using this:

    GL.Begin(GL.LINES);
     GL.Color(Color(1,1,1,1));
     //GL.Vertex3(10,10,1);
     GL.Vertex3(Input.mousePosition.x,Screen.height-Input.mousePosition.y,1);
     GL.Vertex3(100,100,1);
    GL.End();   

and it does nothing, if i use the commented line instead the line with mousposition i get the line but in 3d space, this isnt what i want and i guess that it has to be something with screen space... can somebody help me how to do it?

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 pretender · Oct 23, 2010 at 06:28 PM 0
Share

ok i managed to do it like this:

     GL.Begin(GL.LINES);
         GL.Color(Color(1,1,1,1));
         //GL.Vertex(cam.ScreenToWorldPoint(Vector3(10,10,nearClip)));
         GL.Vertex(cam.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y,nearClip)));
         GL.Vertex(cam.ScreenToWorldPoint(Vector3(100,Screen.height-100,nearClip)));
     GL.End();
avatar image Peter G · Oct 23, 2010 at 06:29 PM 0
Share

Glad to see you fixed it. I posted 2 links right after you typed that. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Peter G · Oct 23, 2010 at 06:28 PM

There are several scripts on the wiki that might help fix yours, or you can use their's.

http://www.unifycommunity.com/wiki/index.php?title=VectorLine

Requires Unity Pro


http://www.unifycommunity.com/wiki/index.php?title=DrawLine

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 pretender · Oct 24, 2010 at 05:37 PM 0
Share

yes, the idea came from the script from your first link, ScreenToWorldPoint seems to does the trick, thanks!

avatar image yoyo · Feb 03, 2011 at 06:42 PM 0
Share

And if you like the idea of drawing 2D lines in your GUI, please vote for my DrawLine feature request ... http://feedback.unity3d.com/forums/15792-unity/suggestions/1451375-gui-drawline

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

using OpenGl to render line works only in Editor not in web player 1 Answer

using openGL to render simple line 1 Answer

Render Line Trailing Player 3 Answers

Drawing a GUI.DrawTexture call above GUI.Button in seperate scripts 0 Answers

renderplugin example not working on ios 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