Function to Setup any bool value

Hi guys,
I’m trying to sync different animators on my networking game.

What I’d like to do is create a method to set my declared bool, something like (just logic code here) :

void SetupBool(bool boolToSet, Value value)

So i can just pass any boolean as a parameter and also true or false.
How would you do that ?

Now, extra effort : I’d like this function to be called on Server with [Command] attribute (I think it messes up with parameters… )

Any input would be really appreciated !
Thanks

Well first off if you wanted to do something like that without worrying about networking its this:

void SetupBool(ref bool boolToSet, Value val)
{
      boolToSet = val;
}

Though if you were passing both the variable to set AND the value you’d just do this instead:

boolToSet = val;

In the calling code and not bother calling that rather redundant method I showed.

I’m not very familiar with UNET at all, but if this is a variable that everyone needs to know about I think what your are looking for is [SyncVar] I believe you can something like this:

public class Settings : NetworkBehaviour
{
          [SyncVar]
          public bool QuickShotEnabled = true;
}

The server then updates this variable to all the clients when it changes. I’m sure there some good tutorials over in the Tutorials section on Unity’s site dealing with using SyncVar in games.
And if that doesn’t get you what you need there is also a UNET forum specifically UNET questions where some more experienced UNET guys could help you with your exact problem.

Hi ! Thank you for the quick reply.
I can’t test it right now but I’m pretty sure I already tried that out and if I remember correctly you can’t pass a ref keyword in a [Command] :frowning:

( the var needs to be changed ON the server to be synced with clients, so you really need the [Command] attribute.

I’m pretty sure thats what SyncVar is for. If a client changes the var it will alert the server to change its value and push that value to all the clients (effectively Trying to set it through command but its all handled behind the scenes)

I’m sure about this one :slight_smile: