简体   繁体   中英

Unity, Client Object Destroying

hey guys so i got a problem with destroying objects over the network as client right so ive got a pickup system where you walk up to objects and pick them up, when you pick them up they are added to your inventory and the item on the ground is destroyed. now this all works fine when your the server picking the items up but when your the client it just simplily doesnt work all it does is add the item to your inventory. now i see things all the time about how just make it a command it is a command and it doesnt seem to work, the items you are interacting with have local player authority and are registered and the player has local player athority but it just doesnt work. this is my script

[Command]
public void CmdAddItem(GameObject hitcollider, int i)

{
    ClientScene.RegisterPrefab (hitcollider);
    NetworkServer.Destroy (hitcollider);
}

i also have done the same thing with a ClientRPC (it is the exact same code and is called the same time as the command) but it still doesnt work thanks

If you want the server to destroy given object it first has to be registered as spawnable prefab on NetworkManager of all clients, it has to have NetworkIdentity and it has to be spawned by server.

If you've already got this then simply call this function:

    [Command]
    public void CmdDestroyObject(NetworkInstanceId netID)
    {
        GameObject theObject = NetworkServer.FindLocalObject (netID);
        NetworkServer.Destroy (theObject);
    }

Where netID is the NetworkInstanceId of the object you want to destroy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM