Host wont take dmg!!,Strugling to get the Host Sync Var to Scyn to clients
Using a take Damage function and the Host doesnt take dmg any help?
public const int maxHealth = 100;
public GameObject SpectateCam;
//public GameObject SpectateSystem;
[SyncVar(hook = "OnChangeHealth")]
public int currentHealth = maxHealth;
public RectTransform healthBar;
public override void OnStartClient()
{
// Create a temporary reference to the current scene.
Scene currentScene = SceneManager.GetActiveScene();
// Retrieve the name of this scene.
string sceneName = currentScene.name;
if (sceneName == "SN_Battle_Royale")
{
SpectateCam.transform.position = new Vector3 (216,140,221);
SpectateCam.transform.parent = null;
}
//SpectateCam.transform.parent = null;
//SpectateCam.transform.position = SpectateSystem.transform.position;
}
public void TakeDamage(int amount)
{
if (!isServer)
{
currentHealth -= amount;
if (currentHealth <= 0)
{
// called on the Server, but invoked on the Clients
Death();
}
}
else
{
Cmd_Dmg(amount);
}
}
[Command]
void Cmd_Dmg(int dmg)
{
Rpc_CurrentHP(dmg);
currentHealth -= dmg;
}
[ClientRpc]
void Rpc_CurrentHP(int dmg)
{
currentHealth -= dmg;
if (currentHealth <= 0)
{
// called on the Server, but invoked on the Clients
Death();
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name =="Water4Simple")
{
Death();
}
}
void OnChangeHealth(int health)
{
healthBar.sizeDelta = new Vector2(health, healthBar.sizeDelta.y);
Cmd_Dmg(currentHealth);
}
void Death()
{
if (isLocalPlayer)
{
SpectateCam.SetActive(true);
}
//gameObject.GetComponent<SCR_Axe_Throwing>().playersdead++;
gameObject.SetActive(false);
gameObject.GetComponent<Animator>().enabled = false;
gameObject.GetComponent<NetworkAnimator>().enabled = false;
}
}
Comment
Your answer
Follow this Question
Related Questions
Camera for 2.5D 2P Platformer 0 Answers
how to make an enemy into a second player 0 Answers
Two Player Shooting game Controller help 0 Answers
Networked scripts mismatch client / host when second player join 1 Answer
How to look left and right with a 2 player controller when up and down is working 0 Answers