- Home /
PlayerPrefs and photon?
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;
}
}
and this
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);
}
}
}
}
@panim0_unity How are you testing with two clients? I recommend to have two Unity versions open, each using a clone of the project where the clone however points at the same origin Assets folder using a symlink. This allows you to get proper debug information on the second client as well, which helps enormously during debugging.
@JPhilipp well I build for android and do the testing , one plays on unity editor and other one n my android device, and sometimes I test with 3 or more devices
and I get no error during testing, it's just If I do some selection from one device all the players units look like that clients choice on its part , and same thing happening for other. They see all units based on their selections