Search Unity

Correct way to stash and and restore recttransform

Discussion in 'Scripting' started by fwalkerCirca, Aug 25, 2018.

  1. fwalkerCirca

    fwalkerCirca

    Joined:
    Apr 10, 2017
    Posts:
    57
    I have a need to stash and restore the recttransform of an object. I don't see an easy way to copy recttransforms so I believe I have to copy the arguments on their own as in:

    Code (CSharp):
    1. public void SetRectTransform(RectTransform aRectTranform)
    2.     {
    3.         if (aRectTranform == null)
    4.             return;
    5.  
    6.         transform.GetComponent<RectTransform>().position = aRectTranform.position;
    7.         transform.GetComponent<RectTransform>().anchoredPosition = aRectTranform.anchoredPosition;
    8.         transform.GetComponent<RectTransform>().localScale = aRectTranform.localScale;
    9.         transform.GetComponent<RectTransform>().rotation = aRectTranform.rotation;
    10.         transform.GetComponent<RectTransform>().sizeDelta = aRectTranform.sizeDelta;
    11.     }

    the question then is. Which variable are the key variables? The ones that are not recalculated by the recttansform and must be copied over?