PlayerPrefs and photon?

Options
Hi
I'm trying to do this:
User can select which skin to use in game so they select this from inventory panel on main menu than they start playing the game. I made this happen by saving string by using PlayerPrefs and attached a script to Player prefab in resources folder to change SetActive() of the game objects named with the string saved by user. Somehow it works n one client but n the other one it doesnt work. I'm sure I tried the shortest cut, it's because it made sense when ı thought it first. Here are my codes::
public class InventroyCtrl : MonoBehaviour
{
    public Text horse;
    public Text jokey;
    public GameObject inventory;
    bool open;
  public void SelectHorse(string name)
    {
        PlayerPrefs.SetString("horse", name);
        horse.text = name;
    }
    public void SelectJokey(string name)
    {
        PlayerPrefs.SetString("jokey", name);
        jokey.text = name;
    }
}

public class SetSkin : MonoBehaviourPunCallbacks
{
    PhotonView photon;
    public GameObject[] horses;
    public GameObject[] jokeys;
    GameObject horse;
    GameObject jokey;
    string horseS;
    string jokeyS;
    // Start is called before the first frame update
    void Start()
    {
        photon = GetComponent<PhotonView>();
        horseS = PlayerPrefs.GetString("horse");
        jokeyS = PlayerPrefs.GetString("jokey");
        if (photon.IsMine)
        {

            for (int i = 0; i < horses.Length; i++)
            {
                if (horses[i].name != horseS)
                {
                    horses[i].SetActive(false);
                }
            }
            for (int i = 0; i < jokeys.Length; i++)
            {
                if (jokeys[i].name != jokeyS)
                {
                    jokeys[i].SetActive(false);
                }
            }

        }

    }

Comments

  • Tobias
    Options
    I am sorry but I don't see the problem right away.
    You need to debug this a little. If you don't want to use debugging via Visual Studio or such, just add some Debug.Log() lines and put in the info you think is relevant.
    Print horseS and in doubt, print each .name value you got in the list.

    Maybe string comparison with != is not fitting. Use .Equals(string).