Hi I have a class called Stats which stores all units stats and I want to sync the player state.
So within my playerScript class which extends NetworkBehaviour, I have a stats class which is also a NetworkBehaviour which within it has a state variable that I want to sync.
Right now I’m getting an error that says:
InvokeCommand class [Stats] doesn’t match [PlayerScript])
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
I read somewhere last night this happens when you have two NetworkBehaviour scripts on an object but I can’t find the link where I read that.
Can I sync this or do I have to put the stuff I want to sync into one NetworkBehaviour?
public class PlayerScript : NetworkBehaviour
{
private Stats _stats;
void UpdateInput()
{
if (Input.GetKeyDown(KeyCode.A))
{
_stats.CmdSetState(Stats.State.Attacking);
}
}
}
public class Stats : NetworkBehaviour
{
public enum State { Attacking, Moving, Idle }
[SyncVar]
public State CurrentState;
[Command]
public void CmdSetState(State state)
{
CurrentState = state;
}
}