My damage script not synchronize from other to other.
How to synchronize my multiplayer fighting game from owner to client? My multiplayer games works fine from Transform view until animator view. But when a player tries to damage on each other, the health points only appear reduced on each client, and not synchronized between clients. If in client 1 player 2 is dead, but in client 2, player 2 is not dead.
This is my Combat Damage Scripts
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; public class dataHP : MonoBehaviourPunCallbacks { public Animator animator; public healthBar hb; public int maxHP = 100; int HPsekarang; // Start is called before the first frame update void Awake() { hb = GetComponent<healthBar>(); } void Start() { HPsekarang = maxHP; hb.SetMaxHealth(maxHP); } // Update is called once per frame void Update() { } public void TakeDamage(int damage) { HPsekarang -= damage; hb.SetHealth(HPsekarang); animator.SetTrigger("isHurt"); if(HPsekarang <= 0) { Die(); } } void Die() { Destroy(gameObject); return; } }
Answers
-
When you paste code, select it and an icon will show on the left side of the input box. Click once and then click the third "quotation marks" icon again. The sub menu will offer to format the selection as code block.
Your code is basically a local game in each client. You have to sync state...
The PUN Basics Tutorial has a very simple implementation of Health Points. Have a look at it.
0