Search Unity

How to calculate object's size

Discussion in '2D' started by Maklaud, Nov 24, 2013.

  1. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    Hi All!

    In Unity 4.3 2d tool we operate with sprites. I need to calculate their size dynamically with these restrictions:
    1. We can't use texture's size (in pixels), because it doesn't matter - we may use the same texture (sprite) for different game objects with different scales.
    2. We can't use local scale, because it may be (1, 1, 1) and the object's size will depend on the texture size and its "Pixels to Units" parameter.
    3. We may differ object size depending on the screen size, for example, for different iOS devices (with different resolutions) - for iPhone they will be smaller, for iPad they will be larger.

    I also know that we can calculate the size with this way:
    Vector3 size = (item.renderer.bounds.max - item.renderer.bounds.min);

    Is it a good way? Is there anything better?

    Thanks!
     
    Last edited: Nov 24, 2013