• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

using openGL to render simple line 1 Answer

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

Switching lines on gui text area 1 Answer

Procedurally generated uGUI elements render under world space objects 1 Answer

Image in Canvas appears behind all GameObjects on 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges