Hi,
I was under the impression that to Destroy an object remotely you had to use NetworkServer.Destroy(gameObject) however, I’m calling GameObject.Destroy(gameObect) on the server and it appears to be destroying the object on the client as well.
Here is my code (bit messy atm):
public class Collidable : NetworkBehaviour {
public bool drawHP = false;
public Texture hpTexture;
[SyncVar]
public int health = 0;
public bool marked = false;
public void Awake() {
this.health = GetComponent<GameData>().getHealth();
}
public void OnTriggerEnter2D(Collider2D collider) {
if (gameObject.layer == LayerMask.NameToLayer("Static") || collider.gameObject.layer == LayerMask.NameToLayer("Static")) {
return;
}
if (collider.gameObject.GetComponent<Ownable>().getOwner() == GetComponent<Ownable>().getOwner()) {
return;
}
//HERE
this.health -= collider.GetComponent<GameData>().getCollisionDamage();
if (base.hasAuthority && this.health <= 0) {
RpcMark();
GameObject.Destroy(gameObject);
}
else if (marked && health <= 0) {
Debug.Log ("Destroyed locally"); //Not getting called
GameObject.Destroy(gameObject);
}
}
[ClientRpc]
public void RpcMark() {
this.marked = true;
}
public override void OnNetworkDestroy() {
Debug.Log ("Destroyed on network."); //Getting called
}
}
This seems very strange to me so sorry if I’m being stupid. What I’m trying to do is have the object be destroyed on the server but not destroyed on the client until the same collision (which is delayed because of latency) happens there as well.