I am trying to alter the sprite of a nested image object within a dialog UI (Unity 4.6's UI) that I have saved as a prefab. I am able to load the prefab, but when I try to do:
Image[] imageComponents = conversationDialogNoChoice.GetComponentsInChildren<Image>();
I get zero items back. The hierarchy is:
The full code is:
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;
}