Version: 2017.2
public double timestamp ;

Description

The time stamp when the Message was sent in seconds.

Timestamps can be used to implement interpolation or extrapolation of continous streams of packets The timestamp is passed as a double to avoid overflow when a game is running for a long time. Internally timestamps are sent as 32 bit integers with millisecond accuracy to save bandwidth. Timestamps are automatically adjusted to be relative to Network.time. Thus Network.time - messageInfo.timeStamp is the time the packet spent in transit.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float something; public double transitTime; void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) { float horizontalInput = 0.0F; if (stream.isWriting) { horizontalInput = transform.position.x; stream.Serialize(ref horizontalInput); } else { transitTime = Network.time - info.timestamp; stream.Serialize(ref horizontalInput); something = horizontalInput; } } void OnGUI() { GUILayout.Label("Last transmission time: " + transitTime); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961