Question by
KaiKristo · Aug 13, 2017 at 05:58 AM ·
unity 5transform.parent
setParent. what am i doing wrong?
I'm trying to create dialog options from the prefab and place them on the UI pane, but ... nothing works. Debug.Log (newOption.GetComponentInParent () .name) displays its name, not the name of the parent
public GameObject optionPrefub;
public GameObject TalkPanel;
public void createOptions()
{
int n = 0;
foreach (DialogOptions Option in DialogTree.curNode.options)
{
GameObject newOption = (GameObject)Instantiate(optionPrefub);
RectTransform optionRect = newOption.GetComponent<RectTransform>();
optionRect.localPosition = TalkPanel.transform.localPosition + new Vector3(0.0f,n*25+5,0.0f);
newOption.name = "Option";
newOption.transform.SetParent(TalkPanel.transform);
newOption.GetComponent<DialogText>().toID = Option.toID.ToString();//
Text optionText = newOption.GetComponentInChildren<Text>();
optionText.text = Option.text;
n++;
}
}
Comment