Hi all!
Im working on part of my game that allows the player to change the characters color. Ive been able to get all the variables to keep their values, but when i relaunch the game, I find that nothing has been saved at all. I have the script set so that automatically if there is no save data, the character will be white, but if that check is passed, then it will load the values saved for the respective RGB codes. If anyone can give some explanation on how this is not working and how to fix it, that would be amazing!
P.S. It is all written in C#
using UnityEngine;
using System.Collections;
public class PlayerColorChange : MonoBehaviour {
static float Red = 0.0F;
static float Green = 0.0F;
static float Blue = 0.0F;
static int FirstPlay = 10;
void Start() {
if(FirstPlay == 10) { //Checks if First Play through of game
Debug.Log("First Playthrough, Either Fresh Install or No Save Data");
Red = 1f;
Green = 1f;
Blue = 1f;
} else {
FirstPlay = 5;
Debug.Log("This Works, Something is not saving correctly!");
}
}
public void ChangeRed(float newRed) { //Changes Red Value
Red = newRed;
}
public void ChangeGreen(float newGreen) { //Changes Blue Value
Green = newGreen;
}
public void ChangeBlue(float newBlue) { //Changes Green Value
Blue = newBlue;
}
// Update is called once per frame
public void Update () {
GetComponent<SpriteRenderer>().color = new Color(Red, Green, Blue, 1f);
}
public void SaveData() {
FirstPlay = 5;
Debug.Log("Save Data Created");
PlayerPrefs.SetInt("FirstPlay", FirstPlay); //Saves the First Playthrough Value
PlayerPrefs.SetFloat("Red", Red); //Saves Red Value
PlayerPrefs.SetFloat("Green", Green); //Saves Green Value
PlayerPrefs.SetFloat("Blue", Blue); //Saves Blue Value
}
}