Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

click and move

Discussion in 'Scripting' started by GMS0012, Mar 27, 2009.

  1. GMS0012

    GMS0012

    Joined:
    Oct 7, 2006
    Posts:
    42
    hi friends

    I am beginner with Unity and I want to solve this problem:

    i have 2 cubes on a ground.
    I want to click on one of them (select it). then I want to click somewhere on my ground and when I release the button, the selected button should move to the clicked position on the ground..

    how can I do this with unity?
    thans for help.
     
  2. donjuan

    donjuan

    Joined:
    Dec 21, 2007
    Posts:
    67
    Hi, you could use a Raycast function to select the cube and also to store the position to which you want to move it. Then to move the cube there are different approaches depending on what you want to do and the components you attached to the cube. One way is by using Vector3.Lerp and other could be Transform.Translate.
    Hope it helps
     
  3. CoherentInk

    CoherentInk

    Joined:
    Jul 16, 2006
    Posts:
    216
    You may also want to have a look at the OnMouseUp function since that will do the raycasting for you.
     
unityunity