- Home /
Adjusting/Adding Sprites During Dialogue
I am currently working on a project where the user interacts with a character in a 2D UI. I have a script that extracts lines from a text file and displays the text within a text box whenever the player presses the Enter/Return key or the left mouse button. However, I'm wondering how I can adjust the sprite shown in the screenshot (i.e. apply a different sprite with a different facial expression based on the text) or add additional sprites in the empty space above the text box.
Thank you for the help in advance!
Answer by YBtheS · Apr 07, 2018 at 07:10 PM
You need to get the Sprite Renderer component from the sprite's GameObject. The reference for the rendered sprite is SpriteRenderer.sprite
so you could do something along the lines of this:
public GameObject spriteGO;
public GameObject newSprite;
void Update() {
if(Some conditions are met) {
spriteGO.GetComponent<SpriteRenderer>().sprite = newSprite;
}
}
I hope that helps!