Executing command in a child GameObject in a multiplayer Game
Hello, I'm developing a 2v2 game with Unity 2017.1 and I don't succeed to fire bullets. I have a PlayerPrefab which is an empty with a network identity component and a NetworkBehaviour script that check the inputs from the local player. The Player prefab has a child (let's name it Perso) which is also an empty but this time with a MonoBehaviour script that execute some methods. One of these methods is Fire which call the CmdFire command of the weapon. The weapon is a child of Perso.
Here's the hierarchy to help you understand : 1>Player 2>Perso 3>Camera 4>Weapon 2>Car (this is the RC Car the player will be able to control. That's why I'm putting Perso inside another empty GameObject).
So now my problem is that I don't succeed to execute my command in the Weapon because :
There is no Network Identity on this object. Please add one.
OK. I add a NetworkIdentity on this GameObject and now "You can't have multiple Network Identity on a single GameObject. There must be only one on the Root". Great.
Does anyone know how to do this? Without putting all the code on the root GameObject because that would be a lot of code and I don't think this is the clean way to do this.
Thanks per advance.
Answer by Riccardo82 · Oct 09, 2017 at 07:14 AM
Same problem. Nobody knows how to have weapons as childs of players and having the firing handled by a script attached on the weapon?
Answer by csharpman · Dec 09, 2020 at 03:40 AM
I have exactly same problem on my project that uses Mirror Networking. Is anybody knows how to solve this problem without changing the structure of my player?
Your answer
Follow this Question
Related Questions
UNet - sync child transform scale 1 Answer
ClientRPC not called from command on client instance during Start() 0 Answers
Photon RPC 2 Answers
Command skipped over on remote clients 0 Answers
UNET NavMeshAgent Sync Target Transform 0 Answers