Hello.
I have GameObjects that will hold sprites. They will change their sprites at certain event. However, pixel sizes of sprites are different.
What I must write in script to keep all changed sprites in one size? (In pixels size is 263x163)
PS this game is on 2D mode.
If you want the sprites to be the same world size even if their pixel size is different, then you need to select the texture used for that sprite and set the ‘Pixels to Units’ value as appropriate to scale the sprite to the target size.
Just change the “pixels per unit” per sprite. To select multiple sprites use the command button (on a mac).
var targetHeight = new Vector3(1f, 1f, 1f); // este tamaño corresponde al que necesites en relación al la primera imagen
var oldSize = icon.sprite.bounds.size.y;
icon.sprite = nodeData.icon;
var newSize = icon.sprite.bounds.size.y;
icon.transform.localScale = (oldSize/newSize) * targetHeight;
This code worked for me, you just have to make sure that the initial target is the scale corresponding to that of the initial image.