Hey There,
I am currently working on a dialogue System with Character Images. Currently what I am trying to implement is on every dialogue in the scriptable object is to have Character Image of the Ai that is speaking. Currently I added in the dialogueNode (see screenshot).
[SerializeField]
Sprite charImage = null;
public Sprite GetImage()
{
return charImage;
}
Currently this had been set to sprite, but in the dialogue UI it needs to change the current sprite Image on the image the assaignd sprite in the scriptable object. This is the code in the player conversant and DialogueUI. Any idea on how I can convert the sprite to change the image source?
PlayerConversant:
public Sprite GetCharacterImage()
{
if (currentNode == null)
{
return null;
}
return currentNode.GetImage();
}
DialogueUI:
private void BuildChoiceList()
{
foreach (Transform item in choiceRoot)
{
Destroy(item.gameObject);
}
choiceRoot.DetachChildren();
foreach (DialogueNode choice in playerConversant.GetChoices())
{
GameObject choiceInstance = Instantiate(choicePrefab, choiceRoot);
var textComp = choiceInstance.GetComponentInChildren<TextMeshProUGUI>();
textComp.text = choice.GetText();
//CharSpeaker Image
Sprite choiceImage = choiceInstance.GetComponent<Image>().sprite = AiImage;
choiceImage = choice.GetImage();
Button button = choiceInstance.GetComponentInChildren<Button>();
button.onClick.AddListener(() =>
{
playerConversant.SelectChoice(choice);
});
}
}