Draw texture the same size of a sprite

I’m working on some enemies for my game and i’ll draw a health bar over then when they’ve taken some damage.

Here’s what i got (this script is linked to the sprite):

Vector3 position = Camera.main.WorldToScreenPoint(new Vector3(transform.position.x, transform.position.y, 0));
Vector3 size = Camera.main.WorldToScreenPoint (transform.renderer.bounds.size);
GUI.DrawTexture(new Rect(position.x,Screen.height-position.y,size.x,size.y), hpBarDetail, ScaleMode.StretchToFill);

The position is almost fine, but the size is messed up. The sprite is small but the texture size is almost the screen size.

How do i draw a texture the same size a sprite is being drawn on the screen?

I found the answer. I made some conversions and got the size i wanted (The height i fixed because it was weird scaling with object’s height)

float vertExtend = Camera.main.orthographicSize;
float horzExtent = vertExtend * Screen.width / Screen.height;
float widthRatio = Screen.width / (horzExtent *2f);
Vector3 size = transform.renderer.bounds.size;
hpBarWidth = transform.renderer.bounds.size.x * widthRatio;
hpBarHeight = Screen.height / 36;
Vector3 position = Camera.main.WorldToScreenPoint(new Vector3(transform.position.x, transform.position.y, 0));
Vector3 size = Camera.main.WorldToScreenPoint (transform.renderer.bounds.size);
GUI.DrawTexture(new Rect(position.x,Screen.height-position.y,hpBarWidth ,hpBarHeight ), hpBarDetail, ScaleMode.StretchToFill);