Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

Switch Modus using PlayerPrefs not working

$
0
0
Hi. I made this script to change the color of the sky and the ground when a button is clicked. This is the function that runs when I click the 'switch modus' button. using UnityEngine; using System.Collections; using UnityEngine.UI; public class BG_ColorChange : MonoBehaviour { string modus; Color32 pink = new Color32(255, 88, 154, 255); Color32 grey = new Color32(156, 160, 160, 255); public void SwitchModus () { GameObject[] skys = GameObject.FindGameObjectsWithTag ("Sky"); GameObject[] floors = GameObject.FindGameObjectsWithTag ("Floor"); modus = PlayerPrefs.GetString ("modus"); if (modus == "night" || modus == null) { PlayerPrefs.SetString ("modus", "day"); foreach (GameObject sky in skys) { sky.GetComponent ().color = Color.white; } foreach (GameObject floor in floors) { floor.GetComponent ().color = Color.white; } } else if (modus == "day") { PlayerPrefs.SetString ("modus", "night"); foreach (GameObject sky in skys) { sky.GetComponent ().color = pink; } foreach (GameObject floor in floors) { floor.GetComponent ().color = grey; } } } } But somehow it is not working. Nothing happens when the switch modus button is clicked. Can someone help? Thanks!!

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>