Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

RectTransform.SetPivotWithCounterAdjust

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public void SetPivotWithCounterAdjust(Vector2 newPivot, bool adjustChildren);

Parameters

Parameter Description
newPivot The normalized position to set for the pivot.
adjustChildren Whether to counter-adjust direct children with Transform components so they remain in place. The default value is false.

Description

Sets the pivot point of the RectTransform, adjusting the position to keep the rectangle in place.

adjustChildren only affects direct children without the RectTransform component, because RectTransform always takes its parent's pivot into account when calculating its position.

using UnityEngine;

public class Example : MonoBehaviour { RectTransform rectTransform;

void Start() { rectTransform = GetComponent<RectTransform>(); }

void Update() { rectTransform.SetPivotWithCounterAdjust(new Vector2(0f, 1f)); } }