Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


IsCoplanarWith(RectTransform)

Determines whether this RectTransform is coplanar with the given RectTransform.
Read time 1 minuteLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public bool IsCoplanarWith(RectTransform target)

Parameters

The RectTransform to test for coplanarity.

Returns

Type

Description

booltrue if this RectTransform is considered coplanar with
target
; false otherwise.

Remarks

Two RectTransforms are considered coplanar when their forward vectors are parallel and they share the same world-space Z position. Use this method to check coplanarity before performing custom logic that requires both RectTransforms to be on the same plane.

Examples

using System.Collections.Generic;using UnityEngine;// Manages which world-space canvas surface is currently active.// Call SetActiveSurface when the player focuses on a different surface —// for example, when a controller ray hits a new canvas.public class SurfaceFocusManager : MonoBehaviour{ [SerializeField] List<RectTransform> m_AllPanels; public void SetActiveSurface(RectTransform focusedPanel) { foreach (RectTransform panel in m_AllPanels) { CanvasGroup group = panel.GetComponent<CanvasGroup>(); bool onActiveSurface = panel.IsCoplanarWith(focusedPanel); // Enable interaction only for panels on the focused surface. group.interactable = onActiveSurface; group.alpha = onActiveSurface ? 1f : 0.5f; } }}