- Home /
How to scale ui image eventually from all sides ?
Hello,
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
Answer by HarshadK · Jul 10, 2017 at 01:20 PM
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;
Your answer
Follow this Question
Related Questions
How to make 2D image's quality better for small objects? 2 Answers
How to update UI image mid-game (Unity, C#) 2 Answers
am trying to scaling my ground size in z direction until my player is moving, 2 Answers
Importing Stripes from Photoshop to Unity 0 Answers
Pull a RawImage from Resources 1 Answer