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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Scale down a SpriteRenderer whilst keeping it's aspect ratio in script?

Discussion in 'Scripting' started by retrophil, Nov 3, 2020.

  1. retrophil

    retrophil

    Joined:
    Mar 16, 2013
    Posts:
    46
    I'm trying to scale a sprite down to a particular set size so all other different res sprites follow suit.

    Not sure how to tackle it... if anyone knows or have any links or clues please let me know, thanks.
     
  2. Shepherd-of-fire

    Shepherd-of-fire

    Joined:
    Oct 9, 2020
    Posts:
    4
    i'm far from an expert but i guess you could try deviding rather than subtracting.
    say you want the scale the Y from 5 to 2 but your X is 8, try the following (not actual script)

    set X to (X / (Y (5) / targertY (2)) (=3.2)
    set Y to targetY (2)

    it's important though that you get your original X and Y before atempting to scale them.
    also i haven't checked my math, might want to change something in the calculations