2D project. I have a GameObject which I use like a container. Rect position is middle-center. While the game is going I add some objects inside this container, hovewer the size doesn’t change. It is 0px widht and height. I have choosen another way to put it right in the center - I know how many object inside this container also I know width and heigth of them. I calculate whole width and whole heigth then divide it on 2 and calculate new Vector3 position in this way:
int horizontalLinesNum = horizontalLines[0].Count;
int verticalLinesNum = verticalLines[0].Count;
float newX = -(horizontalLinesNum*LINE_WIDTH) / 2;
float newY = (verticalLinesNum*LINE_WIDTH) / 2;
Vector3 newPosition = new Vector3 (newX, newY, 0);
this.transform.position = newPosition;
I’ve checked values in debug. It calculates newX = -162; newY = 162; Container appears, but not in posiotion(-162, 162,0). It appears in position(-188.3721, -353.4884, 0);
HOW COME? I can’t understand where it got this numbers. I have stucked with this for a three days. It blows my mind. Guys, please help.