How to scale ui image eventually from all sides ?


now i am using horizontal scrolling menu and when i select any item i want to scale it to be larger.

but when i scale it by the code, it get scaled from right side only … How can i scale it eventually from all sides?

Now i use this function :

		Transform child = _screensContainer.transform.GetChild(index);
		child.localScale = new Vector3(1.3, 1.3, 0f);

I want to make something like in this picture … but i want to be centered and keep its position

It is scaling from the left side because your pivot point is set on the left side (x = 0 and y = 0.5). You can set the pivot to be at center (x = 0.5 and y = 0.5) to get scaling to work from center on all sides.

Something like:

RectTransform child = _screensContainer.transform.GetChild(index) as RectTransform;
// Cache current pivot point.
Vector2 originalPivot = child.pivot;
// Set pivot to center.
child.pivot = new Vector2(0.5f, 0.5f);
// Now scaling should work properly.
child.localScale = new Vector3(1.3, 1.3, 0f);
// Reset the pivot to original pivot.
child.pivot = originalPivot;