O'Reilly logo

Unity Multiplayer Games by Alan Stagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a networked object

Before we can apply interpolation or prediction, we'll need a base to build off of. We'll create a networked object which can be moved around via arrow keys. We'll start with absolutely no interpolation whatsoever—the object instantly appears at the newest location received over the network.

First, let's create a very simple player script.

using UnityEngine;
using System.Collections;

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

  void Update()
  {
    if( networkView == null || networkView.isMine )
    {
      transform.Translate( new Vector3( Input.GetAxis( "Horizontal" ), 0, Input.GetAxis( "Vertical" ) ) * MoveSpeed * Time.deltaTime );
    }
  }
}

This script is very basic. It simply checks if the network view belongs ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required