c# - 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);
}
}
解决方案
推荐阅读
- ms-access - 请帮助我了解访问查询
- mysql - HEAP:删除重复名称并在单个条目中添加值
- scala - 创建 Spark 会话时出现 ClassNotFoundException
- ocaml - 如何使用 ocamlc 选项 -dprofile 和 -dtimings?
- groovy - 如何使用groovy按升序和降序对Ready API中的响应进行排序
- rabbitmq - Django & Celery & Rabbit 出现未注册错误
- arrays - 在视图中传递一个变量,以显示详细信息
- android - Android Retrofit2 返回未找到(404 错误)
- kotlin - Kotlin 中的 Util 类(最佳方法)?
- mongodb - mongoDB聚合:如何使用值作为键