Wrong position using ScreenToWorldPoint

Hello!
I am trying to get my sprite positioned correctly in bottom right corner of the screen using this code in Start(ortho camera):

	float x,y,w,h;
	
	x = Screen.width;
	y = 0;
	
	w = transform.localScale.x * GetComponent<SpriteRenderer>().sprite.texture.width;
	h = transform.localScale.y * GetComponent<SpriteRenderer>().sprite.texture.height;
	
	Vector2 pos = Camera.main.ScreenToWorldPoint(new Vector2(x - w/2, y+h/2 ));		
	transform.position = pos;

Unfortunately, instead of seeing my sprites right bottom corner exactly in the corner of the screen, it is at some distance from the corner (about 20 pixels), fully on screen.
What am i doing wrong? :slight_smile:

These two lines are unlikely to work:

w = transform.localScale.x * GetComponent<SpriteRenderer>().sprite.texture.width;
h = transform.localScale.y * GetComponent<SpriteRenderer>().sprite.texture.height;

The world height and width of a sprite is defined by the Pixels To Units setting and then you need to apply the localScale. Select your sprite texture in the inspector, and you can see the setting for a specific sprite. A better solution would be to use Sprite.bounds. The best solution would be to set the pivot for the sprite to the bottom right. Then you can do:

 transform.position = Camera.main.ViewportToWorldPoint(new Vector3(1,0,0));