Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug I can't use "NetworkBehaviour"

Discussion in 'Linux' started by a872285171, Nov 29, 2016.

  1. a872285171

    a872285171

    Joined:
    Nov 1, 2015
    Posts:
    7
    it happened like this:

    I use UNET to make a small game, when I found that unity3D derived networkbehaviour was not found, perhaps is the namespace problem, but I have already declared namespace, after my test, the project is running and can be exported in window platform,

    I'm using Ubuntu16.04 and 5.4.2f1 unity3d

    Here's the code for the problem:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using System.Collections;
    4.  
    5. public class NetworkSync : NetworkBehaviour {
    6.     //同步速度
    7.     public float lerpSpeed;
    8.     //插值目标位置
    9.     [SyncVar]Vector3 serverSidePosition = Vector3.zero;
    10.  
    11.     void FixedUpdate () {
    12.         if (isLocalPlayer) {
    13.             //发送数据到服务端
    14.             CmdSend2Server (transform.position);
    15.         }
    16.         //执行同步
    17.         LerpPosition ();
    18.     }
    19.  
    20.     [Command]
    21.     void CmdSend2Server(Vector3 position){
    22.         serverSidePosition = position;
    23.     }
    24.  
    25.     //位置同步函数
    26.     void LerpPosition (){
    27.         transform.position = Vector3.Lerp (transform.position, serverSidePosition, lerpSpeed * Time.fixedDeltaTime);
    28.     }
    29. }
     
    Last edited: Nov 29, 2016