- Home /
Question by
tremendo · Oct 06, 2016 at 07:01 PM ·
canvasrecttransformpanel
Problem moving a panel UI
Hi,
Sorry I'm too stupid to find an answer. I searched on forums and tutorial videos and can't find the solution.
I have a UI Panel with UI children: menus and game UI.
What I want to do: push a button and automatically so the camera pans to a position of this panel. I want to have different positions (different menus)
The problem: I can't find out the right size of the panel (or screen) so if I want to interpolate the camera between positions always sets out of position
Canvas: Screen Space Camera • Plane distance : 10 • Canvas Scaler: Scale with Screen Size • Ref. Resolution: 160 x 220 • Match: Width • Ref units: 100 •
void Start ()
{
float co = Screen.height; //canvas.GetComponent<RectTransform> ().rect.height * canvas.scaleFactor;
Vector3 n = Camera.main.ScreenToWorldPoint (new Vector3 (canvas.GetComponent<RectTransform> ().rect.width * canvas.scaleFactor, co, canvas.planeDistance));
heightHUD = n.y;
print ("CO " + co);
}
My coroutine (triggered when a button is pushed) :
while (true) {
yield return new WaitForSeconds (1f);
SlotpParent.SetActive (false);
float movement = Mathf.Lerp (HUD.transform.position.y, heightHUD * 3, (Time.time - startTime) / overTime);
Vector2 pos = new Vector2 (transform.position.x, movement);
HUD.transform.position = pos;
if (HUD.transform.position.y >= heightHUD * 3) {
StopCoroutine ("BringMap");
}
yield return null;
}
yield return null;
}
Comment