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 sanj042 · Jun 07, 2011 at 08:21 AM · texturemousescreenfollowdraw

How to draw a small circle on scene and moving it wherever mouse cursor moves

I want to draw a small circle on screen wherever my mouse cursor moves.

Comment
Add comment · Show 4
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 Kacer · Jun 07, 2011 at 09:06 AM 0
Share

could you provide some more details on what exactly you want?

do you want the circle to follow to the mouse, do you want it in the center of the screen?

avatar image sanj042 · Jun 07, 2011 at 09:14 AM 0
Share

i want the circle to follow the mouse...

avatar image sanj042 · Jun 09, 2011 at 09:13 AM 0
Share

i have line renderer script, i.e a line will be drawn wherever the mouse cursor moves i will paste here var line : LineRenderer; var i:int; var startWidth = 0.001; var endWidth = 0.001; var Line1Trace = new Array(); var LineSize: int = 10;

function Start () { line = this.gameObject.AddComponent(LineRenderer); line.SetWidth(startWidth, endWidth); line.material.color = Color.green; line.renderer.enabled = false; line.SetVertexCount( LineSize ); line.useWorldSpace = true; }

function Update () { var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Line1Trace.length == LineSize) { line.renderer.enabled = true; Line1Trace.shift(); Line1Trace.push( ray.origin + (ray.direction * 1.0)); for( i = 0; i < Line1Trace.length; i++ ) { line.SetPosition( i, Line1Trace[i] ); } } else { line.renderer.enabled = false; Line1Trace.push( ray.origin ); } } it was easy for me,, but now i want a circle to be drawn just like line and it should move where ever the cursor moves, the line should follow the circle

avatar image Joshua · Jun 09, 2011 at 09:15 AM 0
Share

Well you could of use a trailrenderer and spin it around the mouse to have the same effect. But my texture solution is a lot less cpu heavy.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Joshua · Jun 07, 2011 at 12:03 PM

No need for pro. Create a guiTexture. As texture put in an image of a circle (with the rest of the image having an alpha channel so it's invisible). Be sure to put the pixeloffset x and y at minus half of the width/height of the texture, so it's exactly centered. Now just add a script to the guiTexture making it's position relative to the position of the cursor.

Since a guiTexture's transform.position x and y go between 0 and 1 from one side of the screen to the other, and Input.mousePosition x and y go between 0 and screen.width and height you'll want to make the transform.position.x equal to Input.mousePosition.x / Screen.width, and same for the y position.

An example script can be found here. It's a bit overkill for what you want though. You can btw combine this with Screen.showCursor = false to have a custom cursor.

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

Answer by Graham-Dunnett · Jun 07, 2011 at 11:37 AM

If you have Pro, perhaps consider using the GL API to draw your circle as a series of short lines. See:

http://unity3d.com/support/documentation/ScriptReference/GL.LINES.html

The example here draws a line to where the mouse is, so is very close to what you want. If you are not a Pro user, then you might want to use a GUITexture. I think you can use the Pixel Inset to get the positioning to follow the mouse.

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

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

rotate camera on mouse reaching edges 1 Answer

Delta event out of Editor Problem 4 Answers

GUITexture aspect ratio resize 1 Answer

Getting Error "DrawGUITexture: Texture is Null" when using Graphics.DrawTexture in OnGUI() 2 Answers

How to make something happen when mouse on side of screen? 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