Q:

how to get camera width in unity

Problem
I have a spawn manager written in c# which spawns my game object, i use screen.width, to set the maximum screen with and -screen.width to set the minimum screen width for the spawning, but my game object spawns way off the screen.
I am using a portrait camera 2:3 instead of free aspect as my camera view, as i want my game to be in portrait mode
how do i make my game object spawn within the camera widths(max and min)?
my code
public class SpawnManager : MonoBehaviour {

    public int maxBalloons = 100;
    public GameObject balloon;
    public float horizontalMin = -Screen.width;
    public float horizontalMax = Screen.width;
    public float verticalMin = -5.0f;
    public float verticalMax = 1.0f;

    private Vector2 originPosition;

    void Start () {

        originPosition = transform.position;
        Spawn ();

    }

    void Spawn()
    {
        for (int i = 0; i < maxBalloons; i++)
        {
            Vector2 randomPosition = originPosition + new Vector2 (Random.Range(horizontalMin, horizontalMax), Random.Range (verticalMin, verticalMax));

            Instantiate(balloon, randomPosition, Quaternion.identity);
            originPosition = randomPosition;
        }
    }

}

A:

Screen.width and .height give you the current sizes of your game's display/window in pixels.
For positioning objects in our world, we want to work in worldspace units.
When you're using an orthographic camera, camera.orthographicSize gives you the verical half-height of the camera in world units (the distance from the center of the view to the top).
Multiplying that by the camera's width:height aspect ratio, camera.aspect, gives us our half-width in worldspace units.
So you can create your horizontalMin & Max like so:
Camera camera = Camera.main;
float halfHeight = camera.orthographicSize;
float halfWidth = camera.aspect * halfHeight;

horizontalMin = -halfWidth;
horizontalMax =  halfWidth;

For completeness, here's how you'd do it with a perspective camera that gets wider the further back in depth you go. For this we'll need an input depth value representing how far from the camera we want to spawn our objects, along the camera's forward vector.
float halfFieldOfView = camera.fieldOfView * 0.5f * Mathf.Deg2Rad;
float halfHeightAtDepth = depth * Mathf.Tan(halfFieldOfView);
float halfWidthAtDepth = camera.aspect * halfHeightAtDepth;

 // And the rest is the same.

Or you can just compute your desired position in viewport space (from (0,0) in the bottom-left of the camera's view to (1,1) at the top-right) and convert it o a world space position with Camera.ViewportToWorldPoint(), passing your desired depth as the third coordinate. This will automatically handle both perspective and orthographic cameras.

