Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity UI How to copy one Rect Transform data to other Rect Transform

Discussion in 'UGUI & TextMesh Pro' started by timothyfanning, Nov 22, 2020.

  1. timothyfanning

    timothyfanning

    Joined:
    May 1, 2020
    Posts:
    2
    For my game UI requirements, I require to switch TvScreen in Normal and Maximal View/Size based on click of Toggle Button.

    I have just tried to assign one Rect Transform to other Rect Transform but it is not working.

    It just transferring reference data not actual component data like anchor point, pivot, position, scale and rotation.

    I am attaching few images for TvScreen Rect Transform, Normal Screen Size Rect Transform and Maximum Screen Size Rect Transform.

    Tv Screen With Its Rect Transform
    tv screen rect transform.png

    Maximize Screen Size Rect Transform
    Maximize Screen Rect Transform.png

    Normal Screen Size Rect Transform
    Minimize Screen Rect Transform.png

    At present, I have done this but it is not visually changing Tv Screen size.
    Code (CSharp):
    1. public void OnFullscreenMediaButtonClick()
    2. {
    3.     SoundManager.Instance.PlayButtonClickSound();
    4.  
    5.     Debug.Log("maximize button clicked: " + isTvScreenMaximized);
    6.     if (!isTvScreenMaximized)
    7.     {
    8.         isTvScreenMaximized = true;
    9.         tvScreen = maximizeScreenRectTransform;
    10.     }
    11.     else
    12.     {
    13.         isTvScreenMaximized = false;
    14.         tvScreen = normalSizeScreenRectTransform;
    15.     }
    16. }
    I hope you got my question so please give your suggestion related to this.
     
  2. ex-nihilio

    ex-nihilio

    Joined:
    Jan 23, 2015
    Posts:
    12
    If I got the question, you need to set anchorMin, anchorMax values, as described here.