So i have a syncvar called hp
when i remove the hook hphook the syncvar is sent from the server to the client correctly
however as soon as i apply the hook the syncvar is no longer sent from the server to the client
heres the script im stumped
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class Stats : NetworkBehaviour
{
public bool hasbeenattacked;
public List<GameObject> party = new List<GameObject>();
public List<GameObject> attackerslist = new List<GameObject>();
public Transform head;
[SyncVar]
public int level;
[SyncVar(hook = "setname")]
public string username;
[SyncVar(hook = "hphook")]
public float hp;
public bool dualwield;
public GameObject weapontwo;
[SyncVar]
public float currenthp;
public float attacklisttimer;
public float staminacost;
[SyncVar]
public float maxhp;
[SyncVar]
public float stamina;
[SyncVar]
public float currentstamina;
[SyncVar]
public float maxstamina;
public float speed;
public float currentspeed;
public float maxspeed;
public float strength;
public float currentstrength;
[SyncVar]
public string charactername;
public float maxstrength;
public GameObject hpbar;
[SyncVar]
public float damage;
public GameObject shield;
public GameObject weapon;
public Animator anim;
public Slider externalhpbar;
public Slider staminabar;
public Slider externalstaminabar;
public bool checkhp;
public Text nametext;
public GameObject player;
public InputField setcharactername;
public GameObject externalguistamina;
public bool growstamina;
public bool timerstart;
public float timetillfullstamina;
public GameObject arrow;
public float staminagain;
public float staminagaintime;
public float circlevalue;
public Image circlehp;
public AudioClip shieldblock;
public AudioClip gethit;
public AudioClip death;
public AudioClip selectobject;
public AudioSource playeraudio;
public GameObject targeting;
public GameObject nameblock;
public GameObject weaponone;
public GameObject UIuseobject;
[SyncVar]
public bool noshield;
[SyncVar]
public int xp;
[SyncVar]
public int xpgain;
private int originalCount;
[SyncVar(hook = "setplayerdead")]
public bool dead;
public GameObject respawnbutton;
void hphook(float hp)
{
currenthp = hp / maxhp;
externalhpbar.value = Mathf.Lerp(externalhpbar.value, currenthp, 15f);
}
private void setname(string username)
{
nametext.text = username;
}
[Command]
public void Cmd_setname(string charactername)
{
nametext.text = charactername;
Rpc_setname(charactername);
}
[ClientRpc]
public void Rpc_setname(string charactername)
{
nametext.text = charactername;
}
void staminafilling()
{
if (growstamina == true)
{
StartCoroutine(staminafiller());
if (stamina >= maxstamina)
{
growstamina = false;
timerstart = false;
}
}
}
void staminanotfull()
{
if (stamina != maxstamina && timerstart == false)
{
StartCoroutine(staminafill());
}
}
IEnumerator staminafiller()
{
if (growstamina == true && stamina < maxstamina)
{
stamina += staminagain;
yield return new WaitForSeconds(staminagaintime);
StartCoroutine(staminafiller());
if (stamina >= maxstamina)
{
growstamina = false;
timerstart = false;
}
StopCoroutine(staminafiller());
}
}
IEnumerator staminafill()
{
timerstart = true;
yield return new WaitForSeconds(timetillfullstamina);
growstamina = true;
}
void strengthdamage()
{
}
void staminacalculate()
{
currentstamina = stamina / maxstamina;
staminabar.value = Mathf.Lerp(staminabar.value, currentstamina, 15f);
externalstaminabar.value = Mathf.Lerp(externalstaminabar.value, currentstamina, 15f);
}
[Command]
void Cmd_addtoparty(GameObject player)
{
party.Add(player);
}
public void addtoattackers(GameObject player)
{
attackerslist.Add(player);
hasbeenattacked = true;
if (isLocalPlayer)
{
Cmd_addtoattackers(player);
Cmd_attacked(hasbeenattacked);
}
if (isServer)
{
Rpc_addtoattackers(player);
Rpc_attacked(hasbeenattacked);
}
if (hasbeenattacked == true)
{
StartCoroutine(attacklisttime());
hasbeenattacked = false;
if (isLocalPlayer)
{
Cmd_attacked(hasbeenattacked);
}
if (isServer)
{
Rpc_attacked(hasbeenattacked);
}
}
}
public IEnumerator attacklisttime()
{
yield return new WaitForSeconds(attacklisttimer * Time.deltaTime);
if (isLocalPlayer)
{
attackerslist.Clear();
}
if (isServer && transform.tag == "enemy")
{
attackerslist.Clear();
}
}
[Command]
void Cmd_removefromattackers(GameObject player)
{
attackerslist.Remove(player);
Rpc_removefromattackers(player);
}
[ClientRpc]
void Rpc_removefromattackers(GameObject player)
{
{
attackerslist.Remove(player);
}
}
public void restarttime()
{
StopCoroutine(attacklisttime());
StartCoroutine(attacklisttime());
if (isLocalPlayer)
{
Cmd_restarttime();
}
if (isServer)
{
Rpc_restarttime();
}
}
internal void takingthethedamage(float damage)
{
throw new NotImplementedException();
}
[Command]
void Cmd_restarttime()
{
StopCoroutine(attacklisttime());
StartCoroutine(attacklisttime());
Rpc_restarttime();
}
[ClientRpc]
void Rpc_restarttime()
{
StopCoroutine(attacklisttime());
StartCoroutine(attacklisttime());
}
[ClientRpc]
void Rpc_attacked(bool attacked)
{
hasbeenattacked = attacked;
}
[Command]
void Cmd_attacked(bool attacked)
{
hasbeenattacked = attacked;
Rpc_attacked(attacked);
}
[ClientRpc]
void Rpc_addtoattackers(GameObject player)
{
attackerslist.Add(player);
}
[Command]
void Cmd_addtoattackers(GameObject player)
{
attackerslist.Add(player);
Rpc_addtoattackers(player);
}
void setcircle()
{
circlevalue = 1 - currenthp;
circlehp.CrossFadeAlpha(circlevalue, 0.5f, true);
}
public void setplayerdead(bool dead)
{
anim.SetBool("death", dead);
anim.SetBool("lay", dead);
GetComponent<combatmovement>().enabled = !dead;
GetComponent<Regularmovement>().enabled = !dead;
GetComponent<Attackdirection>().enabled = !dead;
if (isLocalPlayer)
{
respawnbutton.SetActive(dead);
}
}
public override void OnStartClient()
{
base.OnStartClient();
setname(username);
if (dead == true && !isServer)
{
anim.SetBool("death", dead);
anim.SetBool("lay", dead);
GetComponent<combatmovement>().enabled = !dead;
GetComponent<Regularmovement>().enabled = !dead;
GetComponent<Attackdirection>().enabled = !dead;
}
}
// Use this for initialization
void Start()
{
if (GetComponent<Charactersize>() != null)
{
if (GetComponent<Charactersize>().weight > 200 && transform.tag != "player")
{
GetComponent<AItargeting>().playertoofar *= 4;
}
}
if (transform.tag == "player")
{
nametext.text = username;
if (isLocalPlayer)
{
Cmd_addtoparty(gameObject);
}
circlehp.canvasRenderer.SetAlpha(0.0f);
}
if (isLocalPlayer)
{
hpbar.SetActive(false);
externalguistamina.SetActive(false);
nameblock.SetActive(false);
}
if (!isLocalPlayer)
{
if (transform.tag == "player")
{
}
}
}
// Update is called once per frame
void Update()
{
if(anim == null)
{
anim = GetComponent<Animator>();
}
if (isServer)
{
staminanotfull();
staminafilling();
}
if(!isLocalPlayer)
{
return;
}
setcircle();
}
}