AndrewRosyaev

SyncCube

Apr 28th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Networking;
  4.  
  5. public class SyncCube : NetworkBehaviour {
  6.  
  7.     [SyncVar]
  8.     private Vector3 syncPos;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.         syncPos = transform.position;
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update ()
  17.     {
  18.         if (isClient)
  19.         {
  20.             transform.position = Vector3.Lerp (transform.position, syncPos, 5 * Time.deltaTime);
  21.         }
  22.         if (isServer)
  23.         {
  24.             transform.Translate (Vector3.forward * Time.deltaTime);
  25.             syncPos = transform.position;
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment