Hi there! I've noticed that the cloned UI images that I instantiate at runtime are misplaced.
***Here's what I have***
I've got Prefabs that are instantiated via script at runtime at a specific position relative to a parent ( which is a child of the main canvas).
Each cloned Prefab is *instantiated to the parent's position, plus the width of all previous clones*.
These prefabs are RectTransform with anchor set to center ( setting pivot and/or position too caused an error about threading and UI), the parent is an empty RectTransform.
Canvas' Canvas Scaler is set to scale with screen size + match width or height.
Here's a chunk of code:
clone.transform.position = position; // a Vector defined outside the loop
slicesRow.Add(clone); //just caching them inside a list
position += new Vector3(clone.GetComponent().sizeDelta.x,0,0);
***Here's what I'd like to do***
I'd like that my clones kept their right positions when playing with a Screen Resolution different than the one expected.
***Here's what I get***
Screen Size expected = ok:
![Screen Size expected][1]
Screen Size other = blargh:
![alt text][2]
**Thanks for your time**, I'm kinda clueless right now and I appreciate your attention
P.S.: about this line ( which is the cause of my problem I guess)
position += new Vector3(clone.GetComponent().sizeDelta.x,0,0);
I know it's better to cache that float value instead of calling it every time, I just don't see the point of optimising a chunk of code that doesn't get the job done ;)
[1]: /storage/temp/47229-screen-shot-2015-05-29-at-010659.png
[2]: /storage/temp/47230-screen-shot-2015-05-29-at-010732.png
↧