Question by
Alacer · Oct 16, 2017 at 05:36 AM ·
multiplayerscript.hook
syncvar hook fires all the time
I was looking for how to update something when syncvar value changed. So i found out about the hook thing, but it seems to fire all the time same as update function - and that would not be a very optimized way of running my game. Is there a better way? I am running unity beta 2017.2.0f2
Comment
Best Answer
Answer by Alacer · Oct 22, 2017 at 09:45 AM
To answer my own question because there does not seem to exsist what im looking for. This way it still works as an update, but does not do anything unless the syncvar value has changed. It will have to do for now.
using UnityEngine.Networking;
public class PlayerSetModel : NetworkBehaviour {
[SyncVar(hook="UpdateModel")] public string modelName;
void UpdateModel(string newModelName)
{
if (newModelName == modelName)
return;
Debug.Log ("Hook function. New modelName = " + newModelName);
modelName = newModelName;
}