Reputation: 157
I'm instantiating a prefab panel in unity and i'm settings it's parent to another panel like this :
GameObject notificationPanel = (GameObject) Resources.Load("NotificationWindow");
Text notificationText = notificationPanel.GetComponentInChildren<Text>();
if (notificationType == NotificationType.Warning)
{
notificationText.color = Color.red;
}
notificationText.text = text;
GameObject newNotificationWindow =
(GameObject) Instantiate(notificationPanel, new Vector3(0, 0, 0), Quaternion.identity);
newNotificationWindow.transform.SetParent(Settings.NotificationHolder.transform);
However when instantiated it's with an insane size, the parent panel has a layout group with a fixed size of the cell's inside of it why isn't this affecting it ? The new panel is around 10 times bigger than my screen. In the hierarchy view the new panel appears as a child correctly under it's parent. Also the 'z' position is around - 3900 why ?
Upvotes: 1
Views: 688
Reputation: 644
So After reading the Unity Documentation: Instantiating the UI element all you have to do is to call:
newNotificationWindow.transform.SetParent(Settings.NotificationHolder.transform, false);
The "false"represents worldPositionStays parameter and this scales the UI.
Let me know if this works for you.
Upvotes: 1