Reputation: 37
I have this code to change colors based on a theme from playerPrefs, and the theme is correctly displayed in the console when I Debug.Log(), but the ifs are not triggering. In the condition for red, I put two logs, but none of them triggered.
For some reason using UnityEngine; and using UnityEngine.UI are not displayed in the code box and the final } isnt displayed there either. There is also a condition for blue similar to the one for red which I took out here to increase readability.
using UnityEngine; using UnityEngine.UI;
public class LoadThemesHome : MonoBehaviour
{
public string theme;
//ALL VARS
public Camera cameraMain;
public Image top;
public Text topText;
public Image timerButton;
public Text timerText;
public Image settingsButton;
public Text settingsText;
public Text info;
public Image bottom;
public Text bottomText;
void Start()
{
if (PlayerPrefs.GetString("theme") != null)
{
theme = PlayerPrefs.GetString("theme");
}
else
{
theme = "black";
PlayerPrefs.SetString("theme", theme);
}
}
private void Update()
{
Debug.Log(theme);
if (theme == "Black")
{
//cameraMain.backgroundColor = new Color(70, 70, 70);
top.color = new Color(0, 0, 0);
topText.color = new Color(255, 255, 255);
timerButton.color = new Color(255, 255, 255);
timerText.color = new Color(30, 30, 30);
settingsButton.color = new Color(255, 255, 255);
settingsText.color = new Color(30, 30, 30);
info.color = new Color(255, 255, 255);
bottom.color = new Color(0, 0, 0);
bottomText.color = new Color(255, 255, 255);
}
else if (theme == "Red")
{
Debug.Log("Start");
//cameraMain.backgroundColor = new Color(0, 0, 185);
top.color = new Color(100, 0, 0);
topText.color = new Color(255, 255, 255);
timerButton.color = new Color(255, 255, 255);
timerText.color = new Color(125, 0, 0);
settingsButton.color = new Color(255, 255, 255);
settingsText.color = new Color(125, 0, 0);
info.color = new Color(255, 255, 255);
bottom.color = new Color(0, 0, 0);
bottomText.color = new Color(255, 255, 255);
Debug.Log("Done");
}
}
}`
Upvotes: 0
Views: 25
Reputation: 71
Try to write these with all lower chars.
for example , write "red" instead of "Red".
Upvotes: 1