how to convert game object pixel height to units

I’ve got a canvas that’s 50 high. I’d like to know how to convert that value to units. I’d like to position this canvas at the bottom of the camera frame. So far I have this code.

    public class JumbotronCanvasController : MonoBehaviour
    {
        // Properties
        private Rigidbody2D rigidBody2D;
        private Camera mainCamera;

        void Start()
        {
            mainCamera = Camera.main;
            rigidBody2D = GetComponent<Rigidbody2D>();
        }

        void FixedUpdate()
        {
            // Follow the camera
            Vector3 camPos = mainCamera.transform.position;
            camPos.y -= mainCamera.orthographicSize;
            //camPos.y += ???;
            rigidBody2D.MovePosition(camPos);
        }
    }

Hi,

don’t user “Camera.main” whereever its possible, reference it through the Inspector directly, making your mainCamera variable public. “Camera.main” is supposed to be slow, as it has to search for it.

Lets say you have a rectangle player - or whatever - sprite.
Then you usually have a Sprite Renderer component on it.
You need to take the bounds of the sprite from the sprite renderer to get the pixels and pass them to your controller.
And then use them in your FixedUpdate() method.

public Bounds currentSpriteBounds;
public void SetCurrentSpriteBounds(Bounds _spriteBounds)
{
    currentSpriteBounds = _spriteBounds;
}

//....
camPos.y += currentSpriteBounds.max.y;


//... and use them somewhere in your code as or similar to
jumbCanController.SetCurrentSpriteBounds(currentGameObject.transform.GetComponent<SpriteRenderer>().sprite.bounds);

KR,
blu3