0

I have a code where if I start click or touch the screen and drag for specific distance does something. I would like to check whenever it is over a specific area (lets say over UI like canvas). The main goal is to have the upper half of the screen to react on click and touch.

I tried to do so by creating new Rect. This works, but I can`t make the rect on upper part of the screen (right now it is on the lower part of the screen). I might be missing something, but the following code should create rect in the upper part of the screen, not ?

if (Input.GetMouseButtonDown(0))
    {
        Rect bounds = new Rect(0, 0, Screen.height / 2, Screen.width);
        if (Input.GetMouseButtonDown(0) && bounds.Contains(Input.mousePosition))
        {
            Debug.Log("Touchableee!");
            TouchableArea = true;
        }

        if (TouchableArea == true)
        {
            tap = true;
            isDraging = true;
            startTouch = Input.mousePosition;
            TouchableArea = false;
        }

    }
    else if (Input.GetMouseButtonUp(0))
    {
        isDraging = false;
        Reset();
    }

Any ideas are welcome, thank you...

1 Answer 1

1

You're starting the Rect at the bottom of the screen, thus why it's on the bottom half.

Parameters

x The X value the rect is measured from.

y The Y value the rect is measured from.

width The width of the rectangle.

height The height of the rectangle.

The following should work for you:

Rect bounds = new Rect(0, Screen.height, Screen.height / 2, Screen.width);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.