Draw Rect - Help I'm newbie

How to make a square or rectangle by moving the mouse it will stop riding and
only when I release the mouse

example

322391--11364--$selection_937.jpg

Use Input.GetMouseButton (0)

to detect whether you are holding the left mouse button.

Use

Input.GetAxis (“Mouse X”)
Input.GetAxis (“Mouse Y”)

to get the X and Y mouse movement since the last frame and add to the X0 Y0 for your rectangle.

ie.

private var recX0;
private var recY0;

function Update()
{
if(Input.GetMouseButton (0))
{
   recX0 += Input.GetAxis ("Mouse X")
   recY0 += Input.GetAxis ("Mouse Y")
}
}

I would use the mouse position to get 2 corners of the box and then you can easily find the other two. This way they are in screen space already. Here is an example. Just put your rectangle texture in as the GUITexture’s tex, or if you have a different way, then remove that and add your own.

var firstPos : Vector2;
var secondPos : Vector2;

var tex : GUITexture;

function Update () {
     if(Input.GetMouseButtonDown(0)) {
        firstPos = Input.mousePosition; // 1st corner
     }

     if(Input.GetMouseButton(0)) {
        secondPos = Input.mousePosition; //opposite corner
        //find other two corners and update rectangle image here.
     }
     
     tex.pixelInset = Rect(firstPos.x, firstPos.y, secondPos.x - firstPos.x, secondPos.y - firstPos.y); 
}

Hmmm I must have interpreted the question incorrectly. I thought you just wanted to move the rectangle around. Otherwise peters solution is much better.