Hello, I’m trying to update a UI image when you click on different buttons. I am currently able to change the UI image only at the start of the game by using C# scripts to set the UI image’s source image to something. I believe I have written the correct code that adds a layer of image changing to change the UI image - basically, I’m able to change the image of the image that directly changes the image of the UI image. When I plug this line of code into Start() it works perfectly. When I put it in a function and assign a button to fire the program when it is clicked on, it doesn’t work. It also doesn’t work when I plug the code into Update() which makes me think that my code only allows for the image change at the start of the game. Here is my code:
"
public Sprite FrogImage;
void Start()
{
}
public void FClickCharacter()
{
GameObject.FindWithTag("ChoosedCharacter").GetComponent<SelectedCharacter>().sprite1 = FrogImage;
}
public void MClickCharacter()
{
}
public void PClickCharacter()
{
}
public void VClickCharacter()
{
}
"
FrogImage is an image I set in Unity, and “SelectedCharacter” is a different script containing “sprite1” which changes the UI image. When I assign FClickCharacter to a button and click the button it doesn’t work. When I put it into Start() the UI image is set to “FrogImage” at the start of the game. When I put it into Update() it just is the original value of sprite1. Any suggestions or tips would be very appreciated, thanks!