Quantcast
Channel: Recent Discussions — Photon Engine
Viewing all articles
Browse latest Browse all 15755

sync values when neutrals attack eachother

$
0
0
None of my gameobjects are controlled by the player. "IsMine" never returns true. How do i sync variables when i don't seem to be able to use isWriting and isReading?
I looked for tutorials to sync health and they all use OnPhotonSerializeView which clearly states:
"To make use of this method, the PhotonStream is essential. It will be in "writing" mode" on the client that controls a PhotonView (PhotonStream.isWriting == true) and in "reading mode" on the remote clients that just receive that the controlling client sends."

Either i'm not implementing it correctly or i am unable to use it in my game due to every unit being controlled by the server. If this concept seems weird just imagine a moba game where neutral creeps are attacking eachother. None of the creeps are controlled by a player. My guess is that i'm simply not implementing it correctly because my transform/rotation is updated correctly on the same object (this object, of course, being controlled by nobody.) In photon view on the object i have the photontransformview (which syncs) and my health script (which doesn't sync.) Here is my health script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Health : Photon.MonoBehaviour {

public float maxHP;
public float currentHP;
public Image healthBar;

void Start () {
maxHP = 100f;
currentHP = maxHP;
}
//called by the person attacking it of course
public void TakeDamage (int damageTaken, GameObject player) {
currentHP = currentHP - damageTaken;
healthBar.fillAmount = currentHP / maxHP;
}

public void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info) {
if (stream.isWriting) {
stream.SendNext (currentHP);
} else if (stream.isReading) {
currentHP = (float)stream.ReceiveNext ();
}
}
}

Viewing all articles
Browse latest Browse all 15755

Trending Articles