Search Unity

Photon Object Control

Discussion in 'Scripting' started by Kamil-Says, Feb 14, 2016.

  1. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    Hey, I have a problem with controlling my player in a room. So basically everything works fine until another player joins the room. If another player joins the game, everything is getting out of control, the weapon controller, plyer damage etc etc. I tried photonview.IsMine but if i do it won't even start the code because photonview is not mine. I tried to enable/disable the scripts on spawning, didn't work too. How can I prevent this control problem 100%?
     
  2. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    you need to post some of your code to get any kind of good response.
     
  3. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    Ok, here:

    Code (CSharp):
    1.  [PunRPC]
    2.     private void InitializeAllWeapons()
    3.     {
    4.         if (AreWeapons(PhotonNetwork.player)) { return; } // if weapons are already registered, get me out of here
    5.         Debug.Log("player reguested weapon initializ: " + PhotonNetwork.playerName); // who requested weapons?
    6.         for(int i=1; i < Slot.Length; i++) // loop trough weapons slots 1-4
    7.         {
    8.                 UnityItem unityItem; // weapon item contains all infos id, name, prefab
    9.                 if (LoadOutManager.TryGetWeaponItem(out unityItem, i)) // try to get item out loadoutmanager
    10.                 {
    11.                        Slot[i] = new WeaponSlot(i, unityItem, attach__, PhotonNetwork.player.ID); // set up slot
    12.                
    13.                        Slot[i].InitializeWeaponItem(); // Initialize weapon
    14.                        RegisterWeapon((byte)i, Slot[i].WeaponID, PhotonNetwork.player.ID); // Register weapon
    15.                 }
    16.                 else
    17.                 {
    18.                     Debug.LogError(string.Format("Failed to initialize weapon slot: {0}", i));
    19.                     //Debug.LogError("unityitem: " + unityItem.name);
    20.                 }
    21.         }
    22.  
    23.         AddRequatedWeapons(PhotonNetwork.player); // tell all weapons were initialized,
    24.     }
    weapon Initialize:
    Code (CSharp):
    1. public void InitializeWeaponItem()
    2.     {
    3.         Debug.Log("initializing weapons!");
    4.         ItemObject = PhotonNetwork.Instantiate(Item.name, Vector3.zero, Quaternion.identity, 0); //Load our weapon object from resourcess folder
    5.         UnityItemManager.AttachWeaponItem(ItemObject, AttachPoint_.transform); // Attach our object as a child to any object
    6.         ItemObject.transform.localPosition = UnityItemManager.SetUpWeaponHelperPosition(ItemObject.transform);//Set up the position of our weapon
    7.         ItemObject.transform.localRotation = UnityItemManager.SetUpWeaponHelperRotation(ItemObject.transform);//Set up the rotation of our weapon
    8.  
    9.     }
     
  4. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    So the problem is everything works fine by the 1st player but if another joins his weapons are invisible for the other clients.