Search Unity

Question Rect Transform hypotenuse inconsistent

Discussion in 'UGUI & TextMesh Pro' started by brockstar512, Apr 30, 2023.

  1. brockstar512

    brockstar512

    Joined:
    May 26, 2020
    Posts:
    3
    I am making a simple tic tac toe game. I'm trying to make the diagonal crosses mobile responsive. Here is the code that I came up with before.
    Code (CSharp):
    1.         holder = this.transform.parent.GetComponent<RectTransform>();
    2.         me = this.transform.GetComponent<RectTransform>();
    3.         float hypotenuse = (float)Math.Sqrt(holder.rect.width * holder.rect.width + holder.rect.height * holder.rect.height);
    4.         Debug.Log(hypotenuse);
    5.         float angle = Mathf.Atan2(holder.rect.width, holder.rect.height) * Mathf.Rad2Deg;
    6.         Debug.Log(angle);
    7.         me.rotation = Quaternion.Euler(0f, 0f, (int)angleType* angle); ;
    8.         me.sizeDelta = new Vector2(me.sizeDelta.x, hypotenuse);
    It worked great last night, but when I woke up this morning it is not. I might have just not really been paying attention last night. The only time this works between screen sizes is when I expand the rect transform to the anchors then center the anchors. Otherwise the width and height of the rect transform the editor is giving me is really small. Screenshot 2023-04-30 at 5.16.47 PM.png Screenshot 2023-04-30 at 5.17.07 PM.png

    Does anyone know where I am misguided or have an alternative solution?