Photon Target : OthersBuffered

Options
aanimation
edited November 2014 in Any Topic & Chat
hi all, i hope anyone can help me as soon as p;

i have problem to sync a value like health float,
i case i have a tower and had health att, so player can attack the tower.
the problems (Networking):
player1 join and attack tower until tower health as 90percent, and then...player2 join too, and have actually same tower as 90percent health,
but...while player2 attack tower until 60percent health'stower, the player1 side, the tower not changes about same tower health.

im using this code :
public class healthTower : Photon.MonoBehaviour 
{

PhotonView pv;
public float currentHP;

void Start () 
	{
		pv = GetComponent<PhotonView> ();
		pv.viewID = 1;
		if(pv.isMine) this.enabled = false;
	}

void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)
	{
		if(stream.isWriting){
			float curHealth = currentHP;
			stream.Serialize(ref curHealth);
		}else	{
			float cHealth = 0;
			stream.Serialize(ref cHealth);}
	}

[RPC]public void ModifTower (float amountHP)
	{
		this.currentHP += amountHP; 
		if(pv.isMine) pv.RPC("ModifTower", PhotonTargets.OthersBuffered, amountHP);
	}

void TestInput ()
	{
		if(Input.GetKeyDown(KeyCode.A))
			ModifTower(-1);
	}

void Update()
	{
		TestInput();
	}
}

Question : whats wrong in my code, what can i do to get best sync values?

notes :
tower not instantiate, i input viewId as manual;
player instantiate by network, viwId by runtime;

im waiting :geek: :ugeek: 8-)

Comments