SetActive onJoinedRoom

Options

Hello everyone, I have an project for a game programming classes and I'm using Photon. So the problem is, onJoinedRoom part I'm Instantiating a prefab in that metod but also I want to change some parts of this prefab with setActive.

public override void OnJoinedRoom()
    {
        GameObject gameObject;
        string s = "PlayerArmature(Clone)/";
        if(PFLogin.prefabName=="Female"){
             gameObject = PhotonNetwork.Instantiate(playerPrefabFemale.name, new Vector3(73, 22, 34), Quaternion.identity, 0,null);
             s = "PlayerArmatureF(Clone)/";
             s += "FemaleCharacterPolyart/";
        }else{
            gameObject = PhotonNetwork.Instantiate(playerPrefab.name, new Vector3(73, 22, 34), Quaternion.identity, 0,null);
            s += "MaleCharacterPolyart/";
        }
        GameObject body = GameObject.Find(s+PFLogin.body);
        GameObject cloak = GameObject.Find(s+PFLogin.cloak);
        GameObject shield = GameObject.Find(s+"root/pelvis/spine_01/spine_02/spine_03/clavicle_l/upperarm_l/lowerarm_l/hand_l/weapon_l/"+PFLogin.shield);
        GameObject weapon = GameObject.Find(s+"root/pelvis/spine_01/spine_02/spine_03/clavicle_r/upperarm_r/lowerarm_r/hand_r/weapon_r/"+PFLogin.weapon);
        body.SetActive(true);
        cloak.SetActive(true);
        shield.SetActive(true);
        weapon.SetActive(true);
        gameObject.GetComponent<ThirdPersonController>().enabled = true;
        PlayerAttack pa = gameObject.GetComponent<PlayerAttack>();
        pa.healthBar = healthBar;
        pa.GameOverScreen = gameOverScreen;
        gameObject.transform.position = new Vector3(73, 22, 34);
        pa.w = image;
        playerCameraRoot = GameObject.FindGameObjectWithTag("Player");
        followCamera.Follow = playerCameraRoot.transform;
        CallAfterDelay.Create(1.0f, loadScreen.Setup2);
        pa.GameOverScreen.Setup2();
        Debug.Log("Connected to the Room");
    }

I want to setActive selectedBody,selectedCloak,selectedShield and selectedWeapon but It's not showing for other players. I want other players to see their body, weapon and cloak, which are different for each player.

Answers

  • Tobias
    Options

    Only one client actually calls PhotonNetwork.Instantiate. Only this client is doing local changes to the object (which are not automagically synced).

    You can either create a component to customize the object on Instantiate (there is a callback for that) and pass "Instantiation Data" to it, or you use some RPC or Custom Properties to sync the values needed to get the same results on all clients...

    The docs should help with the mentioned keywords.