gpt4 book ai didi

How to spawn gameObject on client using NetworkObject.spawn()?(如何使用NetworkObject.spawn()在客户端生成gameObject?)

转载 作者:bug小助手 更新时间:2023-10-28 10:59:39 39 4
gpt4 key购买 nike



NetworkObject.spawn() does not work !
I'm using unity netcode for gameObjects and I try to spawn a gameObjects by instantiating it with the host and then use getComponent().spawn() to instantiate it on the client but that does not work !
The gameObject does not spawn on the client but when I Do "print(NetworkObject.isSpawned)" (on the host) it is returning true.
the prefab I instantiate on the host has a networkObject component and is in the network prefab list of the networkManager and the attached script is a networkBeahviour.

NetworkObject.spawn()不起作用!我正在为游戏对象使用unity netcode,并尝试通过使用主机实例化它来产生一个游戏对象,然后在客户机上使用getComponent().spawn()来实例化它,但这不起作用!GameObject不会在客户机上生成,但当我在主机上执行“print(NetworkObject.isSpawned)”时,它返回TRUE。我在主机上实例化的预置具有一个networkObject组件,位于networkManager的网络预置列表中,附加的脚本是一个networkBeahviour。


I try to find the answer to my question on forum but all of them say that getComponent().spawn() is the way to do.
I want to do things like that because i want to sync the transform of the object on client using NetworkTransform component.
I'm also using unity relay for transport and Unity lobby ( maybe that could be the problem I don't know )
Thanks for the help

我试图在论坛上找到我的问题的答案,但他们都说getComponent().spawn()是解决问题的方法。我想做这样的事情,因为我想使用NetworkTransform组件在客户端同步对象的转换。我也在使用联合接力和联合游说(也许这可能是我不知道的问题)谢谢你的帮助


code :

代码:


GameObject newRock = Instantiate(RockPrefab, transform);
if (GameManager.instance.IsPlayingMultiplayer)
{
newRock.GetComponent<NetworkObject>().Spawn(true);
}

更多回答

Please provide enough code so others can better understand or reproduce the problem.

请提供足够的代码,以便其他人能够更好地理解或重现问题。

优秀答案推荐
更多回答

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com