How To Drag Something From GUI - To Scene - Help

Hello,

I was wondering if there is a way to place an image on a GUI of, say a sphere. And when the user clicks on the 'GUI Sphere' and then drags it onto the scene, an object sphere will follow the mouse until the user places it where ever?

Is this possible? Is it a lot more harder than it sounds?

About My Scene:

I have a camera looking downwards to the scene, with a little GUI window to the left (where the objects/images will be placed.

Would appreciate any help. Thanks

VIDEO:: olliejones.com/GUIHelp.mov

Heres the full script:

var myLeft:float = 0;
var myTop:float = 0;
var myWidth:float = 200;
var myHeight:float = 50;

var isDragging:boolean = false;

function OnGUI()
{
    if (     GUI.RepeatButton( Rect(myLeft, myTop, myWidth, myHeight)  , "Moving Button" )   )
        isDragging = true;

    if (isDragging)
    {
        myLeft = Input.mousePosition.x - myWidth*0.5;
        myTop = Screen.height - (Input.mousePosition.y + myHeight*0.5);
    }
}

function Update(){

    if (    Input.GetMouseButtonUp(0)   )
        isDragging = false;

}

Just replace the words in the button with a texture of your object so it looks like you're dragging stuff.

var myLeft:float = 0;
var myTop:float = 0;
var myWidth:float = 200;
var myHeight:float = 50;

var isDragging:boolean = false;

// Add this line
var myInventoryImg:Texture2D;

function OnGUI()
{
    // if (     GUI.RepeatButton( Rect(myLeft, myTop, myWidth, myHeight)  , "Moving Button" )   )

      // Replace with this
      if (     GUI.RepeatButton( Rect(myLeft, myTop, myWidth, myHeight)  , myInventoryImg )   )
        isDragging = true;

    if (isDragging)
    {
        myLeft = Input.mousePosition.x - myWidth*0.5;
        myTop = Screen.height - (Input.mousePosition.y + myHeight*0.5);
    }
}

function Update(){

    if (    Input.GetMouseButtonUp(0)   )
        isDragging = false;

}

Thx for denewbie…it really works :slight_smile:

BTW 4 oliver jones if you haven’t get it done ( I guess you’d already figure it ou), maybe you’ll want to use custom skin to change the button images :slight_smile: