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
Help is much appreciated.
Thank you for your time as always
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.