So, I’ve got this scene for customizing the color of your player:
.
The player is a prefab that is instantiated in the game scene when it runs, and the materials I am editing in this scene belong to the prefab.
.
When I try it out in the editor, it works perfectly. it saves all of the colors correctly when the game is played, but when I build the game, I try to edit the player, but as soon as I switch scenes to the game, the colors revert to what they originally were.
.
Here is my code:
.
public Renderer Player;
public int Index;
public Color ResetColor;
public Slider Red;
public Slider Green;
public Slider Blue;
public RawImage bg;
private Color color;
void Start(){
color = Player.sharedMaterials[Index].color;
Red.value = color.r;
Green.value = color.g;
Blue.value = color.b;
}
public void Reset(){
Red.value = ResetColor.r;
Green.value = ResetColor.g;
Blue.value = ResetColor.b;
color = ResetColor;
}
void Update(){
bg.color = color;
color.r = Red.value;
color.g = Green.value;
color.b = Blue.value;
Player.sharedMaterials[Index].color = color;
}
.
There is a ColorScript for every body part I am editing, and the public variables are set correctly. Player is the prefab, and I am using sharedMaterials
because of that. I just don’t understand why it works in the editor but not in the build. Can somebody please help me?
Thanks…