unity-game-enginephotonphoton-pun

İn Unity Photon Network , Learn who did the bullet come from?


I make a game using photon network . 2 actors are shooting at each other and when the bullet is formed on the stage I want to know who the bullet came from. I can send player id in bullet Instantiate and I can find player in for loop but i don't think it's true.

Is there better than this method?

Code

    void Shoot()
    {
        var part = GetComponentInChildren<ParticleSystem>();
        part.Play();
        float angle = cc.isFacingRight ? 0f : 180f;

        GameObject gameob = PhotonNetwork.Instantiate("Bullet", firingPoint.position, Quaternion.Euler(new Vector3(0f, 0f, angle)),0, null);
       
    }

Solution

  • You can simply use photonView.Owner, since the bullet is a networked object. Alternatively, you can use photonView.IsMine to check if the client running the check owns the bullet, instead of comparing owners.

    (The photonView instance comes from assuming your bullet script extends MonoBehaviourPun instead of MonoBehaviour)