【发布时间】:2020-07-06 19:01:38
【问题描述】:
我已经为此苦苦挣扎了一两天了。由于某种原因 NetworkServer.Spawn() 似乎不起作用。据我了解,可以从客户端调用 NetworkServer.Spawn() 以在服务器上生成和对象,并且从服务器上,该对象会在所有客户端上生成。目前,当客户端射击时,它只会出现在该客户端上(而不是在服务器上),而当主机射击时,弹丸会在主机和客户端上生成。
代码顶部有一个 using Mirror 标签,该脚本源自 Networkbehaviour。下面这段代码是在客户端调用的:
void Shoot()
{
//Spawn porjectile on local machine
GameObject shot = Instantiate(projectile) as GameObject;
//Set shot projectile position
shot.transform.position = projectilePoint.position;
shot.transform.rotation = transform.rotation;
//Set projectile component of the shot projectile
Projectile shotProjectile = shot.GetComponent<Projectile>();
//Set properties of shot projectile
shotProjectile.damage = damage;
shotProjectile.direction = projectilePoint.position - transform.position;
shotProjectile.speed = projectileTravelSpeed;
shotProjectile.team = team;
shotProjectile.shotBy = gameObject;
NetworkServer.Spawn(shot);
}
有没有人知道为什么射弹没有从客户端生成在服务器上?一个代码示例(在 c# 中)也会很有帮助。
【问题讨论】:
-
看起来网络服务器是第 3 方协议。找不到 Spawn 的任何文档。我确实在网上找到了一个pdf文档:lora gateway to network server interface definition :thethingsnetwork.org/forum/uploads/default/original/1X/…
标签: c# unity-networking