enable disable objects over network

player 1 shoots player 2 , player 1 sees player 2 blow up,player 2 sees bullet next to him but hes not dead, player 2 can shoot and kill player 1 but player 1 cannot see him
any idea why this happens? here is my scripts
using UnityEngine;
using System.Collections;

public class tanknetwork : Photon.MonoBehaviour {

	TankMovementM controllerScript;
	public GameObject tank;
	private Vector3 correctPlayerPos;
	private Quaternion correctPlayerRot;
	void Awake()
	{
		
		controllerScript = GetComponent<TankMovementM>();
		
		if (photonView.isMine)
		{
			
			controllerScript.enabled = true;
		}
		else
		{           
			
			
			controllerScript.enabled = true;
		}
		
		gameObject.name = gameObject.name + photonView.viewID;
	}
	void Update()
	{
		if (!photonView.isMine)
		{
			transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
			transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
		}
	}

	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			// We own this player: send the others our data
			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
			stream.SendNext(tank.active);

		}
		else
		{
			this.correctPlayerPos = (Vector3)stream.ReceiveNext();
			this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
			tank.active = (GameObject)stream.ReceiveNext();
		}
	}
	
	
	
}

using UnityEngine;
using System.Collections;

public class TankMovementM :Photon.MonoBehaviour {
	
	//Movement
	public int speed;
	public int Turnspeed;
	
	//Deafult gun
	public Transform Launcher = null;
	public float ProjectileSpeed;
	public int Clip = 0;
	public bool DefaultGun;
	//MacchineGunShot
	public bool MachineGun;
	public Rigidbody MachineGunBullet = null;
	public float MachineGunSpeed;
	public int MClip = 0;
	public Transform MBulletpos = null;
	public float rateOfFire;
	private float rateOfFireTimer = 0.0f;
	public GameObject MText;
	public Transform MTextLoc;
	//Sounds and paricles
	public GameObject Particle;
	public GameObject Explode;
	public AudioClip Bomb;
	public AudioClip ExplodeSound;
	public AudioClip Shotgun;
	public AudioClip Pistol;



	public Texture real;
	public GameObject body;

	
	void Start () 
	{
		if (photonView.isMine)
		{
			body.renderer.material.mainTexture = real;
		}
		DefaultGun = true;
		MachineGun = false;
		Time.timeScale = 1F;
		cInput.SetKey("BlueTank Forward", "W");
		cInput.SetKey("BlueTank Reverse", "S");
		cInput.SetKey("BlueTank Turn Left", "A");
		cInput.SetKey("BlueTank Turn Right", "D");
		cInput.SetKey("BlueTank Shoot", "LeftControl");
	}
	void Update()
	{
		rateOfFireTimer += Time.deltaTime;
	}
	// Update is called once per frame

	void FixedUpdate () 
	{
		//Movement
		//foward
		if (photonView.isMine)
		{
		if (cInput.GetKey("BlueTank Forward"))
		{
			transform.localPosition += transform.forward * speed * Time.deltaTime;
		}
		//Backwards
		if (cInput.GetKey("BlueTank Reverse"))
		{
			transform.localPosition += -transform.forward  * speed * Time.deltaTime;
		}
		//Rotate Left
		if (cInput.GetKey("BlueTank Turn Left"))
		{
			transform.Rotate(0, -Turnspeed, 0, Space.Self);
		}
		//Rotate Right
			if (cInput.GetKey("BlueTank Turn Right"))
		{
			transform.Rotate(0, Turnspeed, 0, Space.Self);
		}

		//Shooting
		if (Clip == 5)
		{
			DefaultGun = false;
		}
		if (Clip > 5)
		{
			Clip = 5;
		}
		if (MClip == 10)
		{
			MachineGun = false;
			Clip = Clip;
			MClip = 0;
			DefaultGun = true;
		}
		if (MClip > 10)
		{
			MClip = 10;
		}
		
		if (cInput.GetKeyDown("BlueTank Shoot"))
		{
				FireGun();

		}
		if (cInput.GetKey("BlueTank Shoot")&& rateOfFireTimer >= (1/rateOfFire))
		{
			FireMachineGun();
			
		}
		
		}
	}

	void FireGun()
	{
		if (DefaultGun == true)
		{
			Clip = Clip +1 ;
			audio.PlayOneShot(Bomb);
			GameObject part = Instantiate(Particle, Launcher.position, Launcher.rotation)as GameObject;
			GameObject shot =  PhotonNetwork.Instantiate("BulletM", Launcher.position, Launcher.rotation,0) as GameObject;
			shot.rigidbody.AddForce(Launcher.forward * ProjectileSpeed );
			Destroy (part, 1);
		}
	}


	void FireMachineGun()
	{
		if (MachineGun == true)
		{
			Rigidbody shot = Instantiate(MachineGunBullet,MBulletpos.position, MBulletpos.rotation) as Rigidbody;
			shot.AddForce(Launcher.forward * MachineGunSpeed);
			audio.PlayOneShot(Pistol);
			MClip = MClip +1 ;
			rateOfFireTimer = 0.0f;
		}
	}
	
	[RPC]
	void OnCollisionEnter(Collision col) 
	{

		if (col.gameObject.tag == "Projectile")
		{	
		
			GameObject part = Instantiate(Explode, transform.position, transform.rotation)as GameObject;
			AudioSource.PlayClipAtPoint(ExplodeSound,transform.position);
			Destroy (part, 2);
			col.gameObject.SetActive(false);
			gameObject.SetActive (false);

		}
		if (col.gameObject.tag == "Tank")
		{
			GameObject part = Instantiate(Explode, transform.position, transform.rotation)as GameObject;
		//	PhotonNetwork.Destroy(this.gameObject);
			Destroy (part, 2);
		}
		if (col.gameObject.tag == "Ammo")
		{
			audio.PlayOneShot(Shotgun);
			Clip = 0;
			DefaultGun = true;
			col.gameObject.SetActive(false);
		}
		if (col.gameObject.tag == "MachineGun")
		{
			audio.PlayOneShot(Shotgun);
			GameObject part = Instantiate(MText, new Vector3(-8, 0, 0),Quaternion.Euler(90, 0, 0))as GameObject;
			DefaultGun = false;
			MachineGun = true;
			col.gameObject.SetActive(false);
		}
		if (col.gameObject.tag == "Time")
		{
			col.gameObject.SetActive(false);
			Time.timeScale = 0.3F;
		}
	}
}



and this is on the bullet
using UnityEngine;
using System.Collections;

public class Impactm : Photon.MonoBehaviour {


	public int Life;
	public GameObject ball;
	private Vector3 correctPlayerPos;
	private Quaternion correctPlayerRot;

	
	void OnCollisionEnter(Collision col) 
	{
		if (col.gameObject.tag == "Tank")
		{
			//gameObject.SetActive (false);
			col.gameObject.SetActive (false);
			gameObject.SetActive(false);
		}

	}

	void Awake()
	{
		gameObject.name = gameObject.name + photonView.viewID;
	}
	void Update()
	{
		Destroy(gameObject, Life);
		if (!photonView.isMine)
		{
			transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 1);
			transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 1);
		}
	}
	
	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			// We own this player: send the others our data
			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
			stream.SendNext(ball.active);
			
		}
		else
		{
			this.correctPlayerPos = (Vector3)stream.ReceiveNext();
			this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
			ball.active = (GameObject)stream.ReceiveNext();
		}
	}
}

Comments

  • i have also tried using rpcs which still dosent work
    using UnityEngine;
    using System.Collections;
    
    public class TankMovementM :Photon.MonoBehaviour {
    	
    	//Movement
    	public int speed;
    	public int Turnspeed;
    	
    	//Deafult gun
    	public Transform Launcher = null;
    	public float ProjectileSpeed;
    	public int Clip = 0;
    	public bool DefaultGun;
    	//MacchineGunShot
    	public bool MachineGun;
    	public Rigidbody MachineGunBullet = null;
    	public float MachineGunSpeed;
    	public int MClip = 0;
    	public Transform MBulletpos = null;
    	public float rateOfFire;
    	private float rateOfFireTimer = 0.0f;
    	public GameObject MText;
    	public Transform MTextLoc;
    	//Sounds and paricles
    	public GameObject Particle;
    	public GameObject Explode;
    	public AudioClip Bomb;
    	public AudioClip ExplodeSound;
    	public AudioClip Shotgun;
    	public AudioClip Pistol;
    	
    
    	public Texture real;
    	public GameObject body;
    
    	
    	void Start () 
    	{
    
    		if (photonView.isMine)
    		{
    			body.renderer.material.mainTexture = real;
    		}
    		DefaultGun = true;
    		MachineGun = false;
    		Time.timeScale = 1F;
    		cInput.SetKey("BlueTank Forward", "W");
    		cInput.SetKey("BlueTank Reverse", "S");
    		cInput.SetKey("BlueTank Turn Left", "A");
    		cInput.SetKey("BlueTank Turn Right", "D");
    		cInput.SetKey("BlueTank Shoot", "LeftControl");
    	}
    	void Update()
    	{
    
    		rateOfFireTimer += Time.deltaTime;
    	}
    	// Update is called once per frame
    
    	void FixedUpdate () 
    	{
    		//Movement
    		//foward
    		if (photonView.isMine)
    		{
    		if (cInput.GetKey("BlueTank Forward"))
    		{
    			transform.localPosition += transform.forward * speed * Time.deltaTime;
    		}
    		//Backwards
    		if (cInput.GetKey("BlueTank Reverse"))
    		{
    			transform.localPosition += -transform.forward  * speed * Time.deltaTime;
    		}
    		//Rotate Left
    		if (cInput.GetKey("BlueTank Turn Left"))
    		{
    			transform.Rotate(0, -Turnspeed, 0, Space.Self);
    		}
    		//Rotate Right
    			if (cInput.GetKey("BlueTank Turn Right"))
    		{
    			transform.Rotate(0, Turnspeed, 0, Space.Self);
    		}
    
    		//Shooting
    		if (Clip == 5)
    		{
    			DefaultGun = false;
    		}
    		if (Clip > 5)
    		{
    			Clip = 5;
    		}
    		if (MClip == 10)
    		{
    			MachineGun = false;
    			Clip = Clip;
    			MClip = 0;
    			DefaultGun = true;
    		}
    		if (MClip > 10)
    		{
    			MClip = 10;
    		}
    		
    		if (cInput.GetKeyDown("BlueTank Shoot"))
    		{
    				FireGun();
    
    		}
    		if (cInput.GetKey("BlueTank Shoot")&& rateOfFireTimer >= (1/rateOfFire))
    		{
    			FireMachineGun();
    			
    		}
    		
    		}
    	}
    
    	void FireGun()
    	{
    		if (DefaultGun == true)
    		{
    			Clip = Clip +1 ;
    			audio.PlayOneShot(Bomb);
    			GameObject part = Instantiate(Particle, Launcher.position, Launcher.rotation)as GameObject;
    			GameObject shot =  PhotonNetwork.Instantiate("BulletM", Launcher.position, Launcher.rotation,0) as GameObject;
    			shot.rigidbody.AddForce(Launcher.forward * ProjectileSpeed );
    			Destroy (part, 1);
    		}
    	}
    
    
    	void FireMachineGun()
    	{
    		if (MachineGun == true)
    		{
    			Rigidbody shot = Instantiate(MachineGunBullet,MBulletpos.position, MBulletpos.rotation) as Rigidbody;
    			shot.AddForce(Launcher.forward * MachineGunSpeed);
    			audio.PlayOneShot(Pistol);
    			MClip = MClip +1 ;
    			rateOfFireTimer = 0.0f;
    		}
    	}
    	
    
    	void OnCollisionEnter(Collision col) 
    	{
    
    		if (col.gameObject.tag == "Projectile")
    		{	
    		
    			GameObject part = Instantiate(Explode, transform.position, transform.rotation)as GameObject;
    			AudioSource.PlayClipAtPoint(ExplodeSound,transform.position);
    			Destroy (part, 2);
    			Die();
    				
    	
    
    		}
    		if (col.gameObject.tag == "Tank")
    		{
    			GameObject part = Instantiate(Explode, transform.position, transform.rotation)as GameObject;
    			//PhotonNetwork.Destroy(this.gameObject);
    			Destroy (part, 2);
    		}
    		if (col.gameObject.tag == "Ammo")
    		{
    			audio.PlayOneShot(Shotgun);
    			Clip = 0;
    			DefaultGun = true;
    			col.gameObject.SetActive(false);
    		}
    		if (col.gameObject.tag == "MachineGun")
    		{
    			audio.PlayOneShot(Shotgun);
    			GameObject part = Instantiate(MText, new Vector3(-8, 0, 0),Quaternion.Euler(90, 0, 0))as GameObject;
    			DefaultGun = false;
    			MachineGun = true;
    			col.gameObject.SetActive(false);
    		}
    		if (col.gameObject.tag == "Time")
    		{
    			col.gameObject.SetActive(false);
    			Time.timeScale = 0.3F;
    		}
    	}
    	[RPC]
    	void Die()
    	{
    		gameObject.SetActive(false);	
    	}
    }
    
  • also tried using a bool but not sure how to make it work


    using UnityEngine;
    using System.Collections;
    
    public class TankMovementM :Photon.MonoBehaviour {
    	
    	//Movement
    	public int speed;
    	public int Turnspeed;
    	
    	//Deafult gun
    	public Transform Launcher = null;
    	public float ProjectileSpeed;
    	public int Clip = 0;
    	public bool DefaultGun;
    	//MacchineGunShot
    	public bool MachineGun;
    	public Rigidbody MachineGunBullet = null;
    	public float MachineGunSpeed;
    	public int MClip = 0;
    	public Transform MBulletpos = null;
    	public float rateOfFire;
    	private float rateOfFireTimer = 0.0f;
    	public GameObject MText;
    	public Transform MTextLoc;
    	//Sounds and paricles
    	public GameObject Particle;
    	public GameObject Explode;
    	public AudioClip Bomb;
    	public AudioClip ExplodeSound;
    	public AudioClip Shotgun;
    	public AudioClip Pistol;
    	
    
    	public Texture real;
    	public GameObject body;
    	bool dead;
    	
    	void Start () 
    	{
    
    		if (photonView.isMine)
    		{
    			body.renderer.material.mainTexture = real;
    		}
    		DefaultGun = true;
    		MachineGun = false;
    		Time.timeScale = 1F;
    		cInput.SetKey("BlueTank Forward", "W");
    		cInput.SetKey("BlueTank Reverse", "S");
    		cInput.SetKey("BlueTank Turn Left", "A");
    		cInput.SetKey("BlueTank Turn Right", "D");
    		cInput.SetKey("BlueTank Shoot", "LeftControl");
    	}
    	void Update()
    	{
    		if (dead == true)
    		{
    			Die();
    		}
    		rateOfFireTimer += Time.deltaTime;
    	}
    	// Update is called once per frame
    
    	void FixedUpdate () 
    	{
    		//Movement
    		//foward
    		if (photonView.isMine)
    		{
    		if (cInput.GetKey("BlueTank Forward"))
    		{
    			transform.localPosition += transform.forward * speed * Time.deltaTime;
    		}
    		//Backwards
    		if (cInput.GetKey("BlueTank Reverse"))
    		{
    			transform.localPosition += -transform.forward  * speed * Time.deltaTime;
    		}
    		//Rotate Left
    		if (cInput.GetKey("BlueTank Turn Left"))
    		{
    			transform.Rotate(0, -Turnspeed, 0, Space.Self);
    		}
    		//Rotate Right
    			if (cInput.GetKey("BlueTank Turn Right"))
    		{
    			transform.Rotate(0, Turnspeed, 0, Space.Self);
    		}
    
    		//Shooting
    		if (Clip == 5)
    		{
    			DefaultGun = false;
    		}
    		if (Clip > 5)
    		{
    			Clip = 5;
    		}
    		if (MClip == 10)
    		{
    			MachineGun = false;
    			Clip = Clip;
    			MClip = 0;
    			DefaultGun = true;
    		}
    		if (MClip > 10)
    		{
    			MClip = 10;
    		}
    		
    		if (cInput.GetKeyDown("BlueTank Shoot"))
    		{
    				FireGun();
    
    		}
    		if (cInput.GetKey("BlueTank Shoot")&& rateOfFireTimer >= (1/rateOfFire))
    		{
    			FireMachineGun();
    			
    		}
    		
    		}
    	}
    
    	void FireGun()
    	{
    		if (DefaultGun == true)
    		{
    			Clip = Clip +1 ;
    			audio.PlayOneShot(Bomb);
    			GameObject part = Instantiate(Particle, Launcher.position, Launcher.rotation)as GameObject;
    			GameObject shot =  PhotonNetwork.Instantiate("BulletM", Launcher.position, Launcher.rotation,0) as GameObject;
    			shot.rigidbody.AddForce(Launcher.forward * ProjectileSpeed );
    			Destroy (part, 1);
    		}
    	}
    
    
    	void FireMachineGun()
    	{
    		if (MachineGun == true)
    		{
    			Rigidbody shot = Instantiate(MachineGunBullet,MBulletpos.position, MBulletpos.rotation) as Rigidbody;
    			shot.AddForce(Launcher.forward * MachineGunSpeed);
    			audio.PlayOneShot(Pistol);
    			MClip = MClip +1 ;
    			rateOfFireTimer = 0.0f;
    		}
    	}
    	
    
    	void OnCollisionEnter(Collision col) 
    	{
    
    		if (col.gameObject.tag == "Projectile")
    		{	
    		
    			GameObject part = Instantiate(Explode, transform.position, transform.rotation)as GameObject;
    			AudioSource.PlayClipAtPoint(ExplodeSound,transform.position);
    			Destroy (part, 2);
    			dead = true;
    				
    	
    
    		}
    		if (col.gameObject.tag == "Tank")
    		{
    			GameObject part = Instantiate(Explode, transform.position, transform.rotation)as GameObject;
    			//PhotonNetwork.Destroy(this.gameObject);
    			Destroy (part, 2);
    		}
    		if (col.gameObject.tag == "Ammo")
    		{
    			audio.PlayOneShot(Shotgun);
    			Clip = 0;
    			DefaultGun = true;
    			col.gameObject.SetActive(false);
    		}
    		if (col.gameObject.tag == "MachineGun")
    		{
    			audio.PlayOneShot(Shotgun);
    			GameObject part = Instantiate(MText, new Vector3(-8, 0, 0),Quaternion.Euler(90, 0, 0))as GameObject;
    			DefaultGun = false;
    			MachineGun = true;
    			col.gameObject.SetActive(false);
    		}
    		if (col.gameObject.tag == "Time")
    		{
    			col.gameObject.SetActive(false);
    			Time.timeScale = 0.3F;
    		}
    	}
    	[RPC]
    	void Die()
    	{
    		gameObject.SetActive(false);	
    	}
    }
    
  • Sorry for the very late reaction.
    Cool to see the tutorials do help :)