need to know the bullet is coming from which playe

I'm trying to find a way to know which player is shooting at me each player creates a bullet when they shoot and OnCollisionEnter it does damage I want to know which player is shooting.... I know which one is getting shoot but not who is shooting please help here is my OnCollisionEnter function
void OnCollisionEnter (Collision Col)
{

string playername =this.GetComponent().owner.name;
nametak = GameObject.Find("Canvas").GetComponent();

duoon = nametak.duoon;


if (Col.gameObject.tag == "ammo" && view.isMine) 
{


health-=10;

healthinfo = GameObject.Find ("healthinfo").GetComponent ();
healthbar = GameObject.Find ("healthbar").GetComponent ();
healthinfo.text = playername +": " + health + "%";
healthbar.fillAmount = health / 100f;
view.RPC ("damageOther", PhotonTargets.Others, health);


}


}

Comments

  • https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent

    Targets and Parameters
    The PhotonView is like a "target" for the RPC: All clients execute the method only on the networked GameObject with that specific PhotonView. If you hit a specific object and call "ApplyDamage" RPC, then the receiving clients will apply the damage to the same object!

    You can add multiple parameters (provided PUN can serialize them). When you do, the method and the call must have the same parameters. If the receiving client can’t find a matching method, it will log an error.

    There is one exception to this rule: The last parameter of a RPC method can be of type PhotonMessageInfo, which will provide the context for each call. You don't set the PhotonMessageInfo in the call.

    [PunRPC]
    void ChatMessage(string a, string b, PhotonMessageInfo info)
    {
    // the photonView.RPC() call is the same as without the info parameter.
    // the info.Sender is the player who called the RPC.
    Debug.Log(string.Format("Info: {0} {1} {2}", info.Sender, info.photonView, info.timestamp));
    }
    With the sender being in the PhotonMessageInfo and the "targetting" via PhotonView, you can implement shooting someone without extra parameters. You know who shot and what was hit.
Sign In or Register to comment.