Weapon pickups?

Options
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?

Answers

  • bump
  • James_MF
    Options
    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.