我正在尝试更改已保存为预制件的对话框 UI(Unity 4.6 的 UI)中嵌套图像对象的精灵。我可以加载预制件,但是当我尝试这样做时:
Image[] imageComponents = conversationDialogNoChoice.GetComponentsInChildren<Image>();
我得到零物品。层次结构是:
完整的代码是:
private GameObject conversationDialogNoChoice;
public void StartConversation(Conversation conversation)
{
if (!talking)
{
//StartCoroutine(DisplayConversation(conversation));
StartCoroutine(DisplayConversation(conversation));
}
}
IEnumerator DisplayConversationNewUI(Conversation conversation)
{
conversationDialogNoChoice = (GameObject)Resources.Load("Prefabs/ConversationDialogNoChoices");
conversationDialogChoice = (GameObject)Resources.Load("Prefabs/ConversationDialogChoices");
ConversationTest = (GameObject)Resources.Load("Prefabs/ConversationTest");
bool nextPushed;
foreach (var conversationLine in conversation.ConversationLines)
{
nextPushed = false;
Image[] imageComponents = conversationDialogNoChoice.GetComponentsInChildren<Image>();
Debug.Log(imageComponents.Length);
//imageComponents[].sprite = currentCovnersationLine.DisplayPicture;
Instantiate(conversationDialogNoChoice);
while (!nextPushed)
{
if (Input.GetKeyDown(KeyCode.Return))
{
nextPushed = true;
}
yield return null;
}
}
talking = false; //talking is complete
if (conversation.Repeatable == false)
{
conversation.CanOccur = false;
}
yield return null;
}