Get the borders of screen

Hi all!

I move my object and I want to prevent out of bounds the screen. I tryed to use Screen.height an Screen.width, but they are return size in pixels: I am mooving my object in points. My moving method:

void Move()
        {
            var x = gameObject.transform.position.x;
            var y = gameObject.transform.position.y;
            var z = gameObject.transform.position.z;
            
            if (Input.GetKey(KeyCode.W)) gameObject.transform.position = new Vector3(x, y + speed, z);
            if (Input.GetKey(KeyCode.S)) gameObject.transform.position = new Vector3(x, y - speed, z);
            
            if (Input.GetKey(KeyCode.D)) gameObject.transform.position = new Vector3(x - speed, y, z);
            if (Input.GetKey(KeyCode.A)) gameObject.transform.position = new Vector3(x + speed, y, z);
        }

thx

Instead of Screen.height and Screen.width, I think you have to convert the values to world point. Something like:

Vector3 stageDimensions = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height,0));

and then use stageDimensions.x and stageDimensions.y.