x


About gui elements order of activation

Hi, I don't really know how to explain this good enough. I have this code

if (GUILayout.Button("OK"))
    {
        top = y / Screen.height;
        left = x / Screen.width;
        bottom = (y + h) / Screen.height;
        right = (x + w) / Screen.width;
        framing = false;
        showNewConstraint = true;
        Debug.Log("Done");
        return;
    }
    else if (Input.GetMouseButtonDown(0))
    {
        Debug.Log("FirstCorner was: " + firstCorner);
        if (firstCorner)
        {
            drawSelection = false;
            x1 = Input.mousePosition.x;
            y1 = Input.mousePosition.y;
            firstCorner = false;
        }
        else
        {
            x2 = Input.mousePosition.x;
            y2 = Input.mousePosition.y;
            x = Mathf.Min(x1, x2);
            y = Screen.height - Mathf.Max(y1, y2);
            w = Mathf.Abs(x1 - x2);
            h = Mathf.Abs(y1 - y2);
            firstCorner = true;
            drawSelection = true;
        }
        Debug.Log("FirstCorner is: " + firstCorner);
        Debug.Log("X1: " + x1 + " X2: " + x2);

    }

Basically i want this to happen: 1)the user clicks somewhere, x1 and y1 will record where the click happened 2)the users clicks again, x2 and y2 will record the second click, find the top-left click and compute height and width of the rectangle formed by the two clicks 3)when the user clicks OK, record some info and bail out

now, this is what happens after the first click

FirstCorner was: True FirstCorner is: False X1: 530 X2: 0

second click

FirstCorner was: False FirstCorner is: True X1: 530 X2: 729

now after clicking OK

X1: 615 X2: 729 FirstCorner was: False FirstCorner is: True X1: 615 X2: 615 Done

which is not correct. it is like the program jumped in the middle of the else branch even if OK was clicked. Any ideas?

more ▼

asked Aug 16 '10 at 03:24 PM

Patrik gravatar image

Patrik
59 13 13 20

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

0 answers: sort voted first
Be the first one to answer this question
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:

x3667
x948
x71
x55
x5

asked: Aug 16 '10 at 03:24 PM

Seen: 619 times

Last Updated: Aug 16 '10 at 03:24 PM