I am trying to position a sprite based off of mouse position. My code:
void Update ()
{
X = Input.mousePosition.x;
Y = Input.mousePosition.y;
follow.transform.position = new Vector2 (X, Y);
}
“follow” is a public Game Object defined earlier in the code.
The code functions almost as expected, except that if I re-size the Game Scene, follow’s center is no longer positioned at the cursor’s position.
At default 16:9 aspect game scene view:
At 16:9 aspect game scene view that is resized:
I’m relatively new to unity so I’m no expert. I’m guessing that this issue is due to the follow sprite being automatically re-sized based off of the game scene while the mouse-position reference is unaffected by the screen size. Any help would be greatly appreciated, thanks.