Weapon pickups?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Weapon pickups?

LeytonMate
2021-01-31 18:48:59

I'd like my player to be able to pick up weapons from the ground, but I don't know how I should synchronise this. How can I allow weapons to be picked up?

Comments

LeytonMate
2021-02-02 11:27:40

bump

James_MF
2021-02-17 05:45:59

It's really up to you how you should do this. Let's say if you wanted your characters to automatically pickup a weapon when you touch it, you'd do something like this:

private void OnTriggerEnter(Collider other) {  
    if (other.gameObject.tag == "Player")   
        return;  
    if (other.gameObject.GetComponent<PhotonView>().Owner.IsLocal) { //Are we the player that touch this object?  
        int targetPlayerID = photonView.ViewID; // reference to targetPlayer.  
        photonView.RPC("RPC_PlayerPickedUpWeapon", RpcTarget.AllBuffered, targetPlayerID);  
    }  
}  



  
[PunRPC]  
private void RPC_PlayerPickedUpWeapon(int tarPly) {  
    PhotonView tarPlyPV = PhotonView.Find(tarPly);  
    if (tarPlyPV.gameObject != null) { //make sure player is active before proceeding  
        gameObject.transform.parent = tarPlyPV.gameObject.transform; //parent object  
        gameObject.transform.position = Vector3.zero; //reset pos  
        gameObject.transform.rotation = Quaternion.identity; // reset rot  
    }  
}  

Just some untested pseudo code. Hopefully this gives you the right idea.

Back to top