Issue changing button sprites

Hi, I am trying to change button sprite, depenting on the option checked, for Tic Tac Toe game. I made a selection with toggle and I amble to save the choice with PlayerPrefs from 1 scene to other, but when I try to use it with if statement, I am unable to change the ones used. For example, Option 1 uses 0 and 1, Option 2 uses 2 and 3 and Option 3 uses 4 and 5. Below are the images so please if anyone has an idea how to solve it.

void GameSettup()
{
theme = PlayerPrefs.GetString(“Theme”);
if(theme == “Option1”)
{
option = 1;
}
else if (theme == “Option2”)
{
option = 2;
}
else
{
option = 3;
}
Debug.Log("Tema je " + option);
}

Here when I implement if statement to check the options and change the sprite icon to “icons[first]” (First is a value I set myself, depending on the theme chosen, 1, 2 or 4 would be the values)…

public void TicTacToeButton(int whichButton)
{
Spaces[whichButton].image.sprite = icons[whosTurn];
Spaces[whichButton].interactable = false;

    markedSpaces[whichButton] = whosTurn+1;
    turnCount++;

}

I’ll be honest, it’s difficult to understand your setup. I don’t know what “Option” is. I’m not sure how players are interacting with your board nor do I understand the actual issue you are running into.

So what actually is the problem you’re running into? Let’s start there.

I am checking whic toggle is selected and saving that information in PlayerPrefs, then in another scene I load that string and I want to check which one is set and set the theme ( 2 images for buttons representing the X and O) to be the 2 that are coresponding to that choice. The setup is like below…where I use buttons and on click I change the sprite and disable the button.
Icons are the X an O sprites that are supposed to be used.

It looks like you have it figure out on getting your choice to the new scene. In the new scene you will just need a way to check your option and then load up and assign your sprites. There are different ways of doing this, including scriptableobjects, using addressables, defining your sprites directly or even the old Resource.load (and honestly, probably a few others).

1 Like

I manged to solve it with help from a collegue :slight_smile: