- Home /
UNET Buying/changing weapons ingame by players
Hello, I have a problem with instanciating new objects like guns in players hierarchy. I am developing shooting game with equipment shop like in Counter-strike. If I test this feature in Unity (on server), it is working for local player on server (Player1 - host). But If I connect new client (Player2), from client side are problems. Serverside client (Player1) in hierarchy haven't no one gun. I thing I am lost in Command, ClientCallback, ClientRPC atc.
This code should create a gun in player hierarchy but from Player2 it is not created on server and not distributed to clients. Player1 is ok in local, but from Player2 view is not distributed from server. How can i do this?
[Command]
void CmdBuy(GameObject item, int price){
GameObject newItem =(GameObject) Instantiate(item,gunPosition.transform.position,gunPosition.transform.rotation);
newItem.transform.position = gunPosition.transform.position;
newItem.transform.rotation = gunPosition.transform.rotation;
newItem.transform.parent = gunPosition.transform;
newItem.GetComponent<Weapon>().weaponHolder = myGameObject;
NetworkServer.Spawn (newItem);
...
}
And how about next phase of development - switching guns? Thanks
It might help a new part of $$anonymous$$erry Fragmas 2.0 - $$anonymous$$ultiplayer FPS tutorial. Including more things from FPS shooters like switching weapons, buying etc.
Your answer
Follow this Question
Related Questions
【PUN2】I want to disable the instantiation of an object in PhotonView at a specified time. 1 Answer
Adding objects on player models in a multiplayer game 0 Answers
Network Homing Missile 0 Answers
How do NetworkIdentity and Hierarchy interact? 0 Answers
Player object on host can interact with objects, client players cannot. 0 Answers