Problem with PhotonView

Options
Mamul
edited December 2013 in DotNet
The problem is the master client is controlling both players.In my case a player shoots a ball and it has to be teleported to where the ball stopped.When the master client shoots it teleports both players.I tried to enable and disable the scripts with photonView.isMine but nothing happens.Can someone help I'll paste you the code .

This is the first attempt:
[code2=csharp]using UnityEngine;
using System.Collections;

public class enablingScripts : Photon.MonoBehaviour {

// Use this for initialization
void Start () {


if(photonView.isMine){

GetComponent<Shooting>().enabled=true;
}
else{
GetComponent<Shooting>().enabled=false;
}

}

// Update is called once per frame
void Update () {

}
}[/code2]

This is the second.
[code2=csharp]public void OnJoinedRoom()
{

Debug.Log("OnJoinedRoom");
this.marvel=PhotonNetwork.Instantiate("Sphere_prefab" , Vector3.zero , Quaternion.identity,0);
this.Player=PhotonNetwork.Instantiate("First Person Controls" ,Vector3.zero , Quaternion.identity,0);
this.shooting=PhotonNetwork.Instantiate("shooting" ,Vector3.zero , Quaternion.identity,0);
PhotonView myPhotonView = (PhotonView)Player.GetComponent<PhotonView>();
PhotonView myPhotonView2 = (PhotonView)marvel.GetComponent<PhotonView>();
PhotonView myPhotonView3= (PhotonView)shooting.GetComponent<PhotonView>();

//if this is my character -> enable the scripts
if(myPhotonView.isMine && myPhotonView2.isMine && myPhotonView3.isMine ){
(Player.GetComponent("FirstPersonControl") as MonoBehaviour).enabled = true;
(Player.GetComponent("RightTouchPad") as MonoBehaviour).enabled = true;
(Player.GetComponent("LeftTouchPad")as MonoBehaviour).enabled = true;
(shooting.GetComponent("Shooting")as MonoBehaviour).enabled = true;
(Player.GetComponent("SwitchTurns")as MonoBehaviour).enabled = true;
}
//if this is not my character -> disable the scripts
else {
(Player.GetComponent("FirstPersonControl") as MonoBehaviour).enabled = false;
(Player.GetComponent("RightTouchPad") as MonoBehaviour).enabled = false;
(Player.GetComponent("LeftTouchPad")as MonoBehaviour).enabled = false;
(shooting.GetComponent("Shooting")as MonoBehaviour).enabled = false;
(Player.GetComponent("SwitchTurns")as MonoBehaviour).enabled = false;
}[/code2]

Comments

  • The code looks logically very correct. the problem should not happen. I feel there must be a very minute mistake somewhere. I will definitely come back to you if I get anything.
  • I found the problem.I stripped away everything and i left one photon view to see where the problem was.It turns out the object were not instantiated properly in OnJoinedRoom() so i instantiated them in script and its fine now but there is another problem with onPhotonSerializeView() .It seem I'm not getting any data from the other player.

    [code2=csharp]void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)

    {
    if (stream.isWriting)
    {
    //We own this player: send the others our data
    stream.SendNext((bool)Shooting.isMyTurn);
    Debug.Log("Streaming!!!");
    }
    else
    {
    //Network player, receive data
    receiveData = (bool)stream.ReceiveNext();
    Debug.Log(receiveData);
    }
    }[/code2]

    When a room is created the masterclient is first so isMyTurn is set to true and the other client needs to receive that and set its turn to false and vice versa.But on the local client receiveData is false.That means that it isn't receiving the data corectly or doesn't receive it at all.Is there something I'm missing?
  • Tobias
    Options
    Unlike RPCs which can go to all players (optionally), OnPhotonSerializeView is not called locally to read after writing first. It's one or the other.
    Does that match what you're seeing?