I'm using player prefs for my shop system. If i select a skin it gets equipped and then when the player dies the skin reverts back to the default skin. Also, if I restart my game then also skin is not saving and the game loads the old one.
Here is my scripts
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class skinSelection : MonoBehaviour
{
public Renderer skinRender;
public Material mat1, mat2, mat3;
public static bool skinsel1 = false, skinsel2 = false, skinsel3 = false, skinsel4 = false, skinsel5 = false;
public void equip1()
{
Shop.isSkinPur1 = true;
if(Shop.isSkinPur1 == true)
{
skinsel1 = true;
skinsel2 = false;
skinsel3 = false;
skinsel4 = false;
skinsel5 = false;
}
}
public void equip2()
{
Shop.isSkinPur2 = true;
if (Shop.isSkinPur2 == true)
{
skinsel2 = true;
skinsel1 = false;
skinsel3 = false;
skinsel4 = false;
skinsel5 = false;
}
}
public void equip3()
{
Shop.isSkinPur3 = true;
if (Shop.isSkinPur3 == true)
{
skinsel3 = true;
skinsel1 = false;
skinsel2 = false;
skinsel4 = false;
skinsel5 = false;
}
}
public void equip4()
{
Shop.isSkinPur4 = true;
if(Shop.isSkinPur4 == true)
{
skinsel4 = true;
skinsel1 = false;
skinsel2 = false;
skinsel3 = false;
skinsel5 = false;
}
}
public void equip5()
{
Shop.isSkinPur5 = true;
if(Shop.isSkinPur5 == true)
{
skinsel5 = true;
skinsel1 = false;
skinsel2 = false;
skinsel3 = false;
skinsel4 = false;
}
}
}
And the one which saves the selection of skin
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class skinMANAGER : MonoBehaviour
{
public Material skin1, skin2, skin3, skin4, skin5;
public Renderer ballRen;
//string saveSkin = "skinEquipped";
public void skinChanged()
{
if(skinSelection.skinsel1 == true)
{
ballRen.sharedMaterial = skin1;
skinSelection.skinsel2 = false;
skinSelection.skinsel3 = false;
skinSelection.skinsel4 = false;
skinSelection.skinsel5 = false;
_saveSKINS();
}
else
{
Debug.Log("Can't Equip");
}
}
public void skinChanged2()
{
if(skinSelection.skinsel2 == true)
{
ballRen.sharedMaterial = skin2;
skinSelection.skinsel1 = false;
skinSelection.skinsel3 = false;
skinSelection.skinsel4 = false;
skinSelection.skinsel5 = false;
_saveSKINS();
}
else
{
Debug.Log("Can't Equip");
}
}
public void skinChanged3()
{
if(skinSelection.skinsel3 == true)
{
ballRen.sharedMaterial = skin3;
skinSelection.skinsel1 = false;
skinSelection.skinsel2 = false;
skinSelection.skinsel4 = false;
skinSelection.skinsel5 = false;
_saveSKINS();
}
else
{
Debug.Log("Can't Equip/;");
}
}
public void skinChanged4()
{
if (skinSelection.skinsel4 == true)
{
ballRen.sharedMaterial = skin4;
skinSelection.skinsel1 = false;
skinSelection.skinsel2 = false;
skinSelection.skinsel3 = false;
skinSelection.skinsel5 = false;
_saveSKINS();
}
else
{
Debug.Log("Can't Equip");
}
}
public void skinChanged5()
{
if(skinSelection.skinsel5 == true)
{
ballRen.sharedMaterial = skin5;
skinSelection.skinsel1 = false;
skinSelection.skinsel2 = false;
skinSelection.skinsel3 = false;
skinSelection.skinsel4 = false;
_saveSKINS();
}
else
{
Debug.Log("Can't Equip");
}
}
public void _saveSKINS()
{
PlayerPrefs.SetInt("skinEquipped", 1);
PlayerPrefs.Save();
}
}
And yes I'm using playerprefs.get int at start to load my skins. Doesn't work.
↧