Hello there,
I am facing a major problem at the moment with Networking.
I am new to this tpoic, but already read a lot of theory and I think I understood it.
What I do not know is the synatx and I could not find another topic in the forum so far that could help me with that.
Now my problem. I have set up soem code, that allows to set up a Masterserver and up to clients to connect.
Each client controls a capsule and a third-person-camera at the moment.
By pressing “1” they can apply some “Damage” to a cube that has 10 health at the Moment.
When Player 1 now damages the cube he can actually see a healthbar that shows the damage that was done.
But Player 4 e.g. can not see this damage. It is somehow not synchronized.
When Player 1 however “killed” the cube it disappears using “Network.Destroy”. Then it disappears on all clients and the server.
This is the relevant code I use on the cube to parse his health to all clients.
void Update (){
if(Health <= 0){
Network.Destroy(gameObject);
}
}
[RPC]
public void ParseBossHealth(float health){
Debug.Log ("ParsingHealth__ " + health);
networkView.RPC ("ParseBossHealth", RPCMode.All, health);
}
public void applyDamage (float damage){
Health -= damage;
ParseBossHealth (Health);
}
This is the relevant code I use on each player to apply the damage:
//Apply the done Damage to the target
[RPC]
public void DamageTheBoss(float damage){
target.GetComponent<HealthScript> ().applyDamage(damage);
GetComponent<DamageDealt> ().DamageDealtValue += damage;
Debug.Log ("CurrentBossHealth" + currentBossHealth);
}