首页 > 解决方案 > Unity 网络脚本问题

问题描述

我有一个使用 Unity 编辑器构建的多人游戏,但大约是 8 年前。网络内容已在编辑器中更新,我被一个错误所困扰,如下所示:

Assets\General Scripts\Move.cs(58,33):错误 CS0619:“网络”已过时:“旧网络系统已在 Unity 2018.2 中删除。改用 Unity Multiplayer 和 NetworkIdentity。

我已经玩了几个小时了,看来我只是缺少一个“使用”声明。以下是导致错误的代码,任何指针都会有所帮助。

using UnityEngine;
using System.Collections;

public class Move : MonoBehaviour {
     Vector3 velocity;
     int speed;
     string playerClone;
     GameObject Player;
     Transform avatar0;
     public int health;

    // Use this for initialization
    void Start () 
     {
          speed = 3;
          health = 100;
    }
    
    // Update is called once per frame
    void Update () 
     {
          if (health <= 0)
          {
               die();
          }
          if (Input.GetKey("up"))
          {
               velocity = Vector3.forward * speed;
               transform.Translate(velocity * Time.deltaTime);
          }

          if (Input.GetKey("down"))
          {
               velocity = Vector3.back * speed;
               transform.Translate(velocity * Time.deltaTime);
          }
          if (Input.GetKey("left"))
          {

               transform.Rotate(0, -2, 0);
          }

          if (Input.GetKey("right"))
          {
               transform.Rotate(0, 2, 0);
          }
    }

     void OnLoaded()
     {

          Network.Instantiate(avatar0, transform.position, transform.rotation, 0);
          playerClone = "Player(Clone)";

          Player = GameObject.Find(playerClone);
     }

     void OnPlayerDisconnected (Network player)
     {
          Move.Instantiate(Player);
          Network.DestroyPlayerObjects(player);
     }

     void die()
     {
          Destroy(this.gameObject);
     }
}

标签: c#unity3dnetworkingmultiplayer

解决方案


推荐阅读