x


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

more ▼

asked Jan 13 '10 at 09:56 PM

David gravatar image

David
68 3 3 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jan 14 '10 at 01:58 PM

Ashkan_gc gravatar image

Ashkan_gc
9.3k 33 56 120

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3811
x2276
x1001

asked: Jan 13 '10 at 09:56 PM

Seen: 3825 times

Last Updated: Jan 13 '10 at 09:56 PM