Unity 同步局域网内物体匀速移动
做了一个Unity局域网Demo,当一端移动物体时,另外一端同步物体位置,能够匀速不卡顿的方法
public float Speed = 3; private float framSpeed; private float dis; private float pross; private void Update() { if(data!=null &&transform.position!= data.transformData.pos) { framSpeed = Time.deltaTime * Speed; dis = Vector3.Distance(transform.position, data.transformData.pos); pross = 0; if (framSpeed > dis) { transform.position = data.transformData.pos; } else { pross = framSpeed / dis; transform.position = Vector3.Lerp(transform.position, data.transformData.pos, pross); } } }