- Home /
Drag and drop texture
Hi, im working on a script to grab a texture using mouse and move it throught the screen. I want to move different textures to order it.
I have:
void OnGUI() {
if(cont<1) { rect= new Rect(rectx,recty,100,100); } GUI.DrawTexture(rect,Formula1); if(rect.Contains(Event.current.mousePosition)) {
if(Event.current.type == EventType.MouseDrag)
{
Vector2 tempDelta = Event.current.delta;
rectx=tempDelta.x +rectx;
recty=tempDelta.y +recty;
rect = new Rect(rectx,recty,100,100);
cont=1;
//transform.Translate (tempDelta*-0.05f);
}
}
}
With this i can move the texture but always without moving out of the texture or it stops. How can i fix it?
Thanks
Answer by Ashkan_gc · Jan 14, 2010 at 01:58 PM
you can have a variable called "drag" and then make it true when you click on a texture and then move the texture to mouse position till a mouse up event occures.
Your answer
Follow this Question
Related Questions
Specify OnMouseEnter 2 Answers
GUI texture to change texture when hovered over or clicked? 2 Answers
How to check if Mouse is touching GUI Texture 1 Answer
Touchscreen for unity 2 Answers
Wearied Error 1 Answer