Search Unity

Drag

Discussion in 'Scripting' started by nooB, Feb 22, 2010.

  1. nooB

    nooB

    Joined:
    Oct 4, 2009
    Posts:
    20
    I am making a tower of defense style game.
    In this I have created various elements on the GUI.

    I want to drag these elements from the GUI to the game play screen.

    Any ideas on how to do this.
     
  2. greg767

    greg767

    Joined:
    Nov 6, 2009
    Posts:
    113
    Hi,
    I am also quite new to unity, so I don't know if its the best way or not but you could try this.
    So you probably have a sort of image in your GUI window of each item you would like to drop in your 3D field.
    What you could do is to check on what image was a mouse down then check when mouse cursor leaves the GUI window and as soon as it happens you instantiate the GameObject represented by that image at the cursor. Then you raycast from cursor against your terrain when user drags the element around and when there is a mouse release event you place the GameObject at the last raycast.
    So this is my idea, I hope that helps.
    Greg