我正在使用THIS代码将健康拾取器生成到我的场景中,以便任何玩家都可以拾取它们,但是下面的重用代码..
[Command]
void CmdFire()
{
// Set up bullet on server
var bullet = spawnManager.GetFromPool(transform.position + transform.forward);
bullet.GetComponent<Rigidbody>().velocity = transform.forward*4;
// spawn bullet on client, custom spawn handler will be called
NetworkServer.Spawn(bullet, spawnManager.assetId);
// when the bullet is destroyed on the server it wil automatically be destroyed on clients
StartCoroutine (Destroy (bullet, 2.0f));
}
public IEnumerator Destroy(GameObject go, float timer)
{
yield return new WaitForSeconds (timer);
spawnManager.UnSpawnObject(go);
NetworkServer.UnSpawn(go);
}
需要从服务器调用来关闭所有客户端上的运行状况GO,因此,我会在运行状况拾取器生成时抓取运行状况拾取的网络ID,而当客户端将其拾取时,我会使用此代码重新对其进行池化
[Command]
private void CmdReturnToPool ()
{
if (isLocalPlayer)
return;
spawnManagerScript.UnSpawnObject(NetworkServer.FindLocalObject(globalVarsNetworkIDScript.healthNetID));
NetworkServer.UnSpawn(NetworkServer.FindLocalObject(globalVarsNetworkIDScript.healthNetID));
}
但是,仅当您在服务器上将其拾取后,它才会调用重新池。
还尝试了ClientScene.FindLocalObject。
我已经调试了网络ID及其正确的地址。
怎么了?
谢谢。