unity3d - Canvas Screen Scaling with script Instantiated objects? -


can explain me why, when in editor instantiated shop ui looks wonderful (left) when running on device (right), looks squished?, (please excuse dodgy cam picture!):

in editor wonky

the ui bars prefabs, containing individual canvas's , various ui elements. each of canvases manually set use screen scaling, reference resolution set x: 320 y: 480, , set use width basis scaling. has proved work brilliantly in previous games, 1 doesn't seem hold. i've manually set each of instantiated objects' properties scaling in script, still nothing.

the thing i'm doing differently building ui @ runtime instantiating ui prefabs , filling them when shop created.

has seen before? know how fix it?

when instantiate prefab in code , add prefab parent, unity ui system tries compenstate difference between size of prefab when created , size should after canvas scaler update.

when in code use extension:

public static void setparentandreset(this recttransform rect, transform parent) {     rect.setparent(parent);     rect.localscale = vector3.one;     rect.localposition = vector3.zero; } ... var newobj = instantiate(prefab); var rect = newobj.getcomponent<recttransform>(); rect.setparentandreset(parent); rect.localposition = new vector3(1f, 1f, 1f); // set actual position 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -