Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Dynamic shapes based on mouse movement

Discussion in '2D' started by labrat, Dec 30, 2013.

  1. labrat


    Dec 30, 2013
    Is it possible to track mouse movement (while a mouse button is down), record the mouse positions, and then programmatically create a 2D object that has the same shape that the user traced out with the mouse? That is, if the user drags the mouse in a square pattern, the code creates a square object; if they drag the mouse in a circular fashion a circle would be created. It would be best to be able to make any irregular polygon shape.

    I know that Unity 2D doesn't like to draw lines, and I don't think line drawing on the GUI would be helpful since I need the resulting objects to interact with sprites in the game; but I'm hoping that there is some way to create irregular polygon objects in code so that I can just capture mouse movements and convert them into polygon vertices of dynamically created objects.

    Is any of this possible with Unity 2D tools?