Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SetPivotWithCounterAdjust(Vector2, bool)

Sets the pivot point of the RectTransform, adjusting the position to keep the rectangle in place.
Read time 1 minuteLast updated 5 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public void SetPivotWithCounterAdjust(Vector2 newPivot, bool adjustChildren = false)

Parameters

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.

Remarks

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

Examples

using UnityEngine;public class Example : MonoBehaviour{ RectTransform rectTransform; void Start() { rectTransform = GetComponent<RectTransform>(); } void Update() { rectTransform.SetPivotWithCounterAdjust(new Vector2(0f, 1f)); }}