- Home /
Drag and droping from GUI
Hello i so far have an object and a code that will make a gui that when you click on it it will make a copy of that object at 0, 0, 0. I would like it so that when i click n the GUI it will make the object at the location of the mouse and i can move my mouse around and the object follows. Can anyone help me with this i have been searching for a while and nothing has helped so far.
This is my code for making the game object-
var btnTexture : Texture;
var prefab : Transform;
function OnGUI() {
if (GUI.Button(Rect(10,60,50,30),"part1")){
for (var i : int = 0;i < 1; i++) {
Instantiate (prefab, Vector3(i * 2.0, 0, 0), Quaternion.identity);
}
}
}
Answer by Kiwasi · Nov 29, 2014 at 08:40 PM
Stongly suggest upgrading to the latest version of Unity. The UI tools in 4.6 make drag and drop a trivial exercise. Simply add an event trigger for OnDrag, and use that to update transform.position.
Hay soi am a bit new to unity so can you help me out with this?
Your answer

Follow this Question
Related Questions
Is it possible to drag UI item from ScrollRect to elsewhere without mask blocking item? 1 Answer
OnDrag - Object lagging behind the mouse cursor. 0 Answers
Screen space camera makes unity UI object loose track of mouse. 2 Answers
How can I resize an image with drag-and-drop? 1 Answer
How make script many people 0 Answers