What I’ve done:
When you are in the menu you can select dark mode on or off.
If you turn dark mode on and click play, it will send you to a dark theme game scene.
If you turn it off and click play it will send you to a light theme game scene.
As soon as you enter the dark themed game scene a variable “wasSetToDark” will be set to “yes”
If you click back in that scene it will take you to the menu scene where in the start checks if the “wasSetToDark” is “yes” and if it is, it will activate the darkmode.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using System;
using UnityEngine.SceneManagement;
public class MenuScript : MonoBehaviour
{
public GameObject CamPos;
public event Action ChangeToLight;
public event Action ChangeToDark;
public string DarkOrLight = "Light";
public static string wasSetToDark = "no";
public void Start()
{
if (wasSetToDark == "yes")
{
CamPos.transform.position = new Vector3(-6, 0, -25);
DarkOrLight = "Dark";
if (ChangeToDark != null)
{ ChangeToDark(); }
}
}
public void Play()
{
if (DarkOrLight == "Light")
{
SceneManager.LoadScene("GameSceneLight");
}
else
{
SceneManager.LoadScene("GameSceneDark");
}
}
public void DarkMode()
{
if (DarkOrLight == "Light")
{
CamPos.transform.position = new Vector3(-6, 0, -25);
DarkOrLight = "Dark";
if (ChangeToDark != null)
{ ChangeToDark(); }
}
else
{
CamPos.transform.position = new Vector3(-6, 0, 0);
DarkOrLight = "Light";
if (ChangeToLight != null)
{ ChangeToLight(); }
}
}
}
public class wasSetToDarkSETTER : MonoBehaviour
{
void Start()
{
MenuScript.wasSetToDark = "yes";
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEditor;
using System;
public class GameOver : MonoBehaviour
{
MenuScript ThemeChanger;
void Start()
{
ThemeChanger = FindObjectOfType<MenuScript>();
EndMenu.SetActive(false);
}
public void BackToMenuFromGame ()
{
SceneManager.LoadScene("MenuScene");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEditor;
public class TextThemeChanger : MonoBehaviour
{
public GameObject PlayL;
public GameObject OptionsL;
public GameObject QuitL;
public GameObject VolumeL;
public GameObject DarkModeL;
public GameObject BackL;
public GameObject PlayD;
public GameObject OptionsD;
public GameObject QuitD;
public GameObject VolumeD;
public GameObject DarkModeD;
public GameObject BackD;
MenuScript lightset;
MenuScript darkset;
void Start()
{
lightset = FindObjectOfType<MenuScript>();
lightset.ChangeToLight += SetLightTheme;
darkset = FindObjectOfType<MenuScript>();
darkset.ChangeToDark += SetDarkTheme;
}
void SetDarkTheme()
{
PlayD.SetActive(true);
OptionsD.SetActive(true);
QuitD.SetActive(true);
VolumeD.SetActive(true);
DarkModeD.SetActive(true);
BackD.SetActive(true);
PlayL.SetActive(false);
OptionsL.SetActive(false);
QuitL.SetActive(false);
VolumeL.SetActive(false);
DarkModeL.SetActive(false);
BackL.SetActive(false);
}
void SetLightTheme()
{
PlayL.SetActive(true);
OptionsL.SetActive(true);
QuitL.SetActive(true);
VolumeL.SetActive(true);
DarkModeL.SetActive(true);
BackL.SetActive(true);
PlayD.SetActive(false);
OptionsD.SetActive(false);
QuitD.SetActive(false);
VolumeD.SetActive(false);
DarkModeD.SetActive(false);
BackD.SetActive(false);
}
}
My problem is:
public void Start()
{
if (wasSetToDark == "yes")
{
CamPos.transform.position = new Vector3(-6, 0, -25);
DarkOrLight = "Dark";
if (ChangeToDark != null)
{ ChangeToDark(); }
}
}
Here,
if (ChangeToDark != null)
{ ChangeToDark(); }
This wont work.
Maybe a video could help you understand the problem:
723zrb
Btw I just started coding so please explain clearly ![]()