5.3.3 Get Position and Size of a Panel
Hello!
So i have a scene like this, with plenty of panels and layout control components on them. I wish to use them as waypoints while moving cards around, since they can be conviniently rescaled. It's probably not the most proper way to use GUI, but i didn't expect so much trouble there.
The problem is, i can't get actual position or size of these panels in runtime, at all. I tried
var firstPlayerHand = GameObject.Find("First Player Hand");
var position1 = firstPlayerHand.transform.position;
var position2 = firstPlayerHand.GetComponent<RectTransform>().rect;
The first one returns coordinates, that means little to me. More over, it returns the same coordinates for every GUI element i try it on. To be precise, it's (-10.7, -5.0, 0.0).
The second one returns empty rectangle.
Would be great if someone could enlighten me on what's going on here.
Answer by khaldinks · Sep 06, 2016 at 04:08 PM
Alright, silly me. I've read positions at the start, but it takes atleast one frame to set them up. So after the first Update() everything is good to go.