How to PunRPC a new weapon on a character if Photon is mine OnTriggerEnter?

Options
Hi,

In my multiplayer game, the player can get a new weapon by flying through a crate that contains the new weapon.

I realize I'm doing two different things that aren't working in my code below for examples sake here it is:

Code (CSharp):
  [PunRPC]
    void OnTriggerEnter(Collider other)
    {
        if (photonView.isMine)
        {
 
            if (other.tag == "BeeSting")
        {
                photonView.RPC("BeeStingMissileNew", PhotonTargets.Others, beePrefab);
                bee.SetActive(true);
                beePrefab.SetActive(true);
            }
I check if photon is mine on trigger enter. If it is, the "bee.SetActive(true);" (which is an icon in the top right corner) and "beePrefab.SetActive(true);" (which is the actual missile prefab that is an inactive child object on the player) become active. They don't show to anybody else in the game, but the beePrefab should.

The other thing I'm doing is trying to RPC the "BeeStingMissileNew" which is the prefab in the Resources folder to all other players in the game so they can see my weapon, but I'm not specifying its position and that's not the prefab I'd like to show all other clients.

How do I PunRPC the child object prefab called "beePrefab.SetActive(true);" so that all players can see that it is now active?

I hope this makes sense and that someone can tell me what I'm doing wrong. Thank you

Comments

  • petersenjmp
    Options
    is there anybody that can help?
  • petersenjmp
    Options
    Nobody or is this forum dead_?
  • igorLira
    igorLira
    edited July 2019
    Options
    GetComponent of something, like one script attached
  • igorLira
    Options
    I'm a begenner, but I'll try to help.
    I think you dont need to use RPC to create a obj from a prefab, but PhotonInstatiate.
    See the differents in use of OnTriggerEnter and OnCollisonEnter! Maybe it'd be the problem.
    Try to not use Tag, but check the object from a component attached, like a script.
    For example:

    void OnCollisionEnter2D(Collision2D col)
    {
    var comp = col.gameObject.GetComponent();
    if (comp && col.gameObject != player)
    {
    _TargetFounded = true;
    playeratacked = col.gameObject;

    }

    //I'm trying to avoid using tag's because they're strings !
    // if (col.gameObject.tag == "Player" && col.gameObject != player){ _TargetFounded = true; }
    }
  • petersenjmp
    Options
    Hey, Thanks for your help. It definitely has to be RPC'ed as it is not an instantiated object, but a child object that is simply activated. Anytime you want to show changes in-game to all other players you have to send those changes via RPC. I just don't know exactly how to write it within the trigger event, but I appreciate your answer nonetheless. Have a great day .-)