Skip to content

Feedback for ocs/tutorials/goldenpath_series/gp_module_two.md #805

Closed
@j-flammia

Description

@j-flammia

### Issue:
There is no reference to a ClientNetworkVariable to obtain a value from its value property, or any mention of it in the "Debug.Log" statements, yet the output of the test in console says:

"Server's var initialized to: 0
Server set its var to: 0.1, has client var at: 0
Server set its var to: 3.099999, has client var at: 2.6
Server set its var to: 6.099997, has client var at: 5.599997"

### Current Code:

using Unity.Netcode;
using UnityEngine;

public class NetworkVariableTest : NetworkBehaviour
{
    private NetworkVariable<float> ServerNetworkVariable = new NetworkVariable<float>();
    private float last_t = 0.0f;

    public override void OnNetworkSpawn()
    {
        if (IsServer)
        {
            ServerNetworkVariable.Value = 0.0f;
            Debug.Log("Server's var initialized to: " + ServerNetworkVariable.Value);
        }
    }

    void Update()
    {
        var t_now = Time.time;
        if (IsServer)
        {
            ServerNetworkVariable.Value = ServerNetworkVariable.Value + 0.1f;
            if (t_now - last_t > 0.5f)
            {
                last_t = t_now;
                Debug.Log("Server set its var to: " + ServerNetworkVariable.Value);
            }
        }
    }

}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions