Photon view problem?

I am having difficulties with the photon view.I’m trying to enable and disable script using
photonView.isMine but it seem I’m doing nothing.Can someone help me or explain to me how exactly it works and how to disable those scripts because now the master client is controlling everything.This is a sample of the code :

 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;
			}

and I also tried this :

public class enablingScripts : Photon.MonoBehaviour {

// Use this for initialization
void Start () {


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

There are photonViews attached to the objects and the photonview on the shooting object is set to observe the shooting.cs script.Any ideas?

anybody? :/

1 Answer

1

I use UnityScript(JS). But this should easily convert over to C#.

I get this problem too. And I find the best way to fix it. Is to create a variable that gets set to the “PhotonView” in the start function, Like this.

var PV: PhotonView;

function Start(){
    PV = gameObject.GetComponent(PhotonView);
}

function WhatEverFunctionYouWant(){
   if(PV.isMine){
      //Do Something
   }
}