Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to create a NetworkVariable which is writable for everyone?

Discussion in 'Netcode for GameObjects' started by chuilishi, Nov 12, 2023.

  1. chuilishi

    chuilishi

    Joined:
    Nov 20, 2022
    Posts:
    3
    I'm working on a button when both player click on it,game start.
    so I just create a script which is spawned by host, and within there is a NetworkVariable<int>,if someone click on it,it will add 1. As it's value reach to the sum of client,game start.
    The problem is it seems that there is no way to allow everyone to change the same networkVariable.
    even I had used serverRpc(RequireOwnership = false) and writepermission is server, if I'm not owner I still can't change the value.

    P.S.
    the networkvariable is spawned on server like this:

    Code (CSharp):
    1. NetworkManager.Singleton.OnServerStarted += () =>
    2.         {
    3.             foreach (var NGO in networkPrefabs)
    4.             {
    5.                 var ngo = Instantiate(NGO);
    6.                 ngo.Spawn();
    7.             }
    8.         };
     
  2. chuilishi

    chuilishi

    Joined:
    Nov 20, 2022
    Posts:
    3
    sorry,this problem has been solved