Preparing for server authoritative movement

Before we get started, we'll need to restructure our scripts. We're going to change the Update function so that it isn't called automatically, and instead will be called by our networking scripts. We need to do this so that we have direct control over the exact order in which the simulation is stepped, otherwise we can easily end up with desyncs and rubber banding.

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
  public float MoveSpeed = 5f;

  [System.NonSerialized]
  public float horizAxis = 0f;
  [System.NonSerialized]
  public float vertAxis = 0f;

  void Update()
  {
    if( networkView.isMine )
    {
      horizAxis = Input.GetAxis( "Horizontal" );
 vertAxis = Input.GetAxis( "Vertical" ...

Get Unity Multiplayer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.