I create a script with a simple syncvar and get UNetWeaver error message “UNetWeaver error: SyncVar Hook function ChangeHP must have one argument CharacterBehaviour”.
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class CharacterBehaviour : NetworkBehaviour {
public int maxHp = 100;
public Slider hpBar;
[SyncVar(hook = "ChageHp")]
public int curHp;
public void ChangeHp(){
hpBar.value = curHp;
}
}
What “Synch Var” does is it sends the value that uses “Synch Var” to a function when the value changes, So as your code states, Unity tries to send the “curHp” value to a function (ChangeHp) but the function doesn’t accept the value, so Unity is telling you to add one (Int) argument to the function.
Thus the working script should be something like this:
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class CharacterBehaviour : NetworkBehaviour {
public int maxHp = 100;
public Slider hpBar;
[SyncVar(hook = "ChageHp")]
public int curHp;
public void ChangeHp(int _curHp){
hpBar.value = _curHp;
}
}