HVutov
April 24, 2015, 5:33pm
1
Im trying to add prefab to canvas and it look like this in scene view i have to change LEFT,TOP,RIGHT,BOTTOM to 0 to show the gameObject properly but i dont know how
GameObject talkBox = (GameObject)Instantiate(box);
RectTransform boxRect = talkBox.GetComponent<RectTransform>();
talkBox.transform.parent = canvas.transform;
boxRect.transform.localScale = new Vector3(1, 1, 1);
talkBox.GetComponent<RectTransform>().localPosition = new Vector3(0,0,0);
You should use
talkBox.GetComponent<RectTransform>().rect = new Rect(LEFT, TOP, RIGHT, BOTTOM);
Kiwasi
April 24, 2015, 7:49pm
3
What are left, right, top and bottom set to on your prefab? They shouldn’t change.
You may need to use SetParent to get this to work. One of the bool settings prevents the RectTransfom from automatically updating.
HVutov
April 25, 2015, 11:41am
4
Kiwasi:
What are left, right, top and bottom set to on your prefab? They shouldn’t change.
You may need to use SetParent to get this to work. One of the bool settings prevents the RectTransfom from automatically updating.
left, right, top and bottom are 0 on the prefab but they get changed runTime and i dont know how
I set parent here talkBox.transform.parent = canvas.transform;
HVutov
April 25, 2015, 11:46am
5
I fix it the problem was anchors i set the in the middle and its ok now