- Home /
Question by
OxygenInvestor · Apr 16, 2020 at 11:54 AM ·
dragmouse position
2D Mouseposition returning wrongly scaled values when in fullscreen, versus windowed.
So I have some code shown below. When I apply an arbitrary modifier of 1.75 to divide the mouse position, I get a (mostly) correct position of the mouse and gameobject. I am wondering what the proper method would be to fix this problem.
Basically the gameobject I drag is out of place, and I can't seem to find any answers googling for help.
void Update()
{
if (isDragging)
{
if (MainMenu.fullScreen)
{ transform.position = new Vector2(Input.mousePosition.x / (float)1.75, Input.mousePosition.y / (float)1.75); }
//So I have no idea why dividing by 1.75 works. 1.75 is an arbitrary divider that negates my fullscreen glitch.
else if(!MainMenu.fullScreen)
transform.position = new Vector2(Input.mousePosition.x , Input.mousePosition.y );
transform.SetParent(Canvas.transform, true);
}
}
Comment
Your answer
Follow this Question
Related Questions
Drag object with mouse in diagonal direction 1 Answer
How to drag Unity Objects to other c# application 0 Answers
Prevent Drag button inside scroll rect 0 Answers
Mouse Movement Combat System 0 Answers
Fire at Mouse Position, 2d game. 2 Answers