- Home /
Question by
jaanonim · Jan 31, 2019 at 03:06 PM ·
uiinstantiatecanvasscrollview
Incorrect positioning of the UI element from script
Hello,
Through the script, I add further elements of the list, after What scales the content of the object from the Scroll View to make the list fills in it. The problem is when I change the screen's focus, because then the elements will be on top of each other (game will work on Android).
public void spawn(Vector2 sPos)
{
Vector2 contentMove = new Vector2();
Vector2 lastPos = sPos;
int x = 0;
foreach (LevelData.level iD in data.typ)//for all elements of the list
{
GameObject now = Instantiate(buttonO, lastPos,Quaternion.identity, parent);// parent -> content
contentMove.x += move.x;
contentMove.y += move.y;
lastPos += move;
now.SendMessage("setNumber", x);
x++;
}
content.sizeDelta = new Vector2(content.sizeDelta.x -contentMove.x, content.sizeDelta.ycontentMove.y);//resize content
}
Pleace help! Mateusz
beztytułu.png
(164.0 kB)
bezdtytułu.png
(291.8 kB)
Comment
Your answer
Follow this Question
Related Questions
Grid and Canvas react on mouse events simultaneously 0 Answers
Instantiating UI element on Screen space - Overlay not instantiating exact specified location 0 Answers
Movement in Scroll View 0 Answers
Scroll view/rect broken on Android only 0 Answers
UI Text does not show when instantiated at runtime. 0 Answers