c# - Unity 5.4.2 - Scale and position instantiated UI elements -


so i've been working on project class i'm in , have run pickle can't seem resolve. have asked instructor , confused was.

right i've been trying set simple ui displaying list of buttons select level load. @ runtime code creates appropriate buttons , such, , places them within scrollview's content object. simple enough, right? well, as can see position , right wrong, 800 units.

the canvas set screen space - overlay , canvas scaler set scale screen size, i'm guessing problem. had problem of position , scale being more off (depending on screen size), "fixed" manually setting transform's position , localscale.

i have had no luck finding solution this, googling, i'd appreciative if me , explain me problem is.

here code executes each of levels. it's of course messy because i've been trying as figure out problem is.

        level thislevel = levelmanager.levellist [i];         gameobject levelbutton = (gameobject)instantiate (menumanager.levelbuttoncontainerobject);          levelbutton.transform.setparent (menumanager.mainmenulevelcontainer.transform, false);         levelbutton.transform.position = vector3.zero;         levelbutton.transform.localposition = vector3.zero;         levelbutton.transform.localscale = vector2.one;          recttransform levelbuttonrect = levelbutton.getcomponent<recttransform> (); //          levelbuttonrect.position = applycanvasscale (new vector3 (0f, -50 + (-100 * i), 0f));         levelbuttonrect.position = new vector3(0f, -50 + (-100 * i), 0f); //          levelbuttonrect.position = vector3.zero;         levelbuttonrect.sizedelta = new vector2 (0f, 100f);         debug.log ("position " + levelbuttonrect.position + ", scale " + levelbuttonrect.sizedelta); 

try adding these you're setting position , scale:

levelbutton.transform.offsetmin = vector2.zero levelbutton.transform.offsetmax = vector2.zero 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -