Mouse Placement in Screen issue / Need Help.

I am unsure on the topic so I figured I should ask the helpful folk at Unity Answers. What I want to do is make an if statement which asks whether the mouse position is in a certain area of the screen.

I am completely unsure on how to do this
So I have

   mousePlacement = Input.mousePosition;

Which defines where my mouse is and

screenCentre = new Vector3(Screen.width * 0.5f,0,Screen.height * 0.5f);

which defines where the screen centre is. So what I want to do if possible is an iff statement asking whether the mousePlacement is in a certain area of the screen. Im unsure how to do this or if it is possible. For instance is the mouse somewhere in the left centre, the top left, the bottom left, middle top, middle centre, middle bottom, right top, right middle, right bottom. If you get me :confused:

Help is much appreciated.

Thank you for your time as always :slight_smile:

EDIT: Update

I did what you put and got errors so I edited it to my code and it worked. But the only area I could get going was the one that you put down angle > 0 && angle < 90 im debugging it by print messages is there anyway you could define which angles of the screen are which parts. Notice that I changed it away from using the x axis as my screen look down to x and z.

screenCentre = new Vector3(Screen.width * 0.5f,0,Screen.height * 0.5f);
Vector3 offset = Input.mousePosition - screenCentre;
	float angle = Mathf.Atan2(offset.z, offset.x) *Mathf.Rad2Deg;
	float radius = offset.magnitude;
	if(angle > 0 && angle < 90){
	// The mouse must be in the top-right side of the screen!
		print("lol");
		}
	if(angle > 90 && angle < 180){
		print("haha");
		}

This time Haha comes up but not lol.

Well, already with what you have you can do a pretty good job of it!

First off, subtract the middle of the screen from the mouse position to get an 'offset' value.

Vector2 offset = (Vector2)Input.mousePosition - new Vector2(Screen.width / 2, Screen.height / 2);

Now, you can translate this offset into polar coordinates, to get an angle and a radius-

float angle = Mathf.Atan2(offset.y, offset.x) * Mathf.Rad2Deg;
float radius = offset.magnitude;

Now that you have the angle, you can use that to determine what quadrant the mouse is in!

if(angle > 0 && angle < 90)
{
    // The mouse must be in the top-right side of the screen!
}