Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Make Sprite Renderer fit the screen size

Discussion in 'Editor & General Support' started by Rachan, Jul 28, 2023.

  1. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    654
    Hi there!

    I really want to know, how to adjust a sprite renderer scale fit to Screen.width and Screen.height,

    it similar to Canvas UI RectTramsform by stretch all axis

    my sprite renderer just simple game object with Transform component, Not RectTransform in UI Canvas

    there is possible?

    Thanks!!!
     
    Last edited: Jul 28, 2023
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Ortho camera is easy. Go look at the Camera.orthographicSize property for what it means, and match your sprite.

    Perspective camera requires knowing distance to camera, then using trig functions on the .fieldOfView to compute how large "the entire screen" is at that depth.
     
    Rachan likes this.
  3. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    654
    Thank you very much!
     
    Kurt-Dekker likes this.