RPC - Null Reference Exception

Options
I'm trying to make multiplayer game like Air Hockey and I can shoot the ball with master but I can't shoot the ball with client. I've tried the owner transfer but with this solution ball moves awkward and laggy. I'm just found out the RPC and I'm trying to implement it but It gives Null Reference.

Here is my script:

using System.Collections;
using System.Collections.Generic;
using Photon.Pun;
using UnityEngine;


[RequireComponent(typeof(PhotonView))]
    public class ShootControl : MonoBehaviourPun
    {
        [SerializeField]
        private Color effectColor = Color.white;

        [SerializeField]
        private string targetTag = "Ball";

        [SerializeField]
        private bool bindCollision = false;

        [SerializeField]
        private float power = 5f;

        [SerializeField]
        private float Multiplier { get; set; } = 1;

        private Rigidbody2D target;
        private PhotonView pv;

    void Start()
    {
        pv = GetComponent<PhotonView>();
    }


    

        
        [PunRPC]
        public void Shoot(float pushForce)
        {

        //effectRenderer.color = effectColor;
        //Invoke("ResetColor", 0.2f);
        if (target != null)
            {
            target.AddForce(DirectionVector * pushForce * 200);
            }
        }

        private void ResetColor()
        {
            //effectRenderer.color = Color.black;
        }

    private Vector2 DirectionVector
    {
        get
        {
            Vector3 direction = transform.position - target.gameObject.transform.position;
            return -direction.normalized;
        }
    }

    [PunRPC]
    private void OnTriggerEnter2D(Collider2D collision)
        {
            if (!bindCollision && collision.gameObject.CompareTag(targetTag))
            {
                target = collision.gameObject.GetComponent<Rigidbody2D>();
            target.GetComponent<PhotonView>().RequestOwnership();
            target.GetComponent<PhotonView>().TransferOwnership(GetComponent<PhotonView>().Owner);
        }
        }
    [PunRPC]
    private void OnTriggerStay2D(Collider2D collision)
        {
            if (!bindCollision && collision.gameObject.CompareTag(targetTag))
            {
                target = collision.gameObject.GetComponent<Rigidbody2D>();
            }
        }
    [PunRPC]
    private void OnTriggerExit2D(Collider2D collision)
        {
            if (!bindCollision && collision.gameObject.CompareTag(targetTag))
            {
                target = null;
            }
        }
    [PunRPC]
    private void OnCollisionEnter2D(Collision2D collision)
        {
            if (bindCollision && collision.gameObject.CompareTag(targetTag))
            {
                target = collision.gameObject.GetComponent<Rigidbody2D>();
            }
        }
    [PunRPC]
    private void OnCollisionStay2D(Collision2D collision)
        {
            if (bindCollision && collision.gameObject.CompareTag(targetTag))
            {
                target = collision.gameObject.GetComponent<Rigidbody2D>();
            }
        }

    [PunRPC]
    private void OnCollisionExit2D(Collision2D collision)
        {
            if (bindCollision && collision.gameObject.CompareTag(targetTag))
            {
                target = null;
            }
        }

    void Update()
    {
        if (!pv.IsMine)
        {
            return;
        }
        if (Input.GetKeyDown(KeyCode.Space) && Shootable)
        {
            Vector3 pos = transform.position + transform.forward * 2f;
            Vector3 angle = transform.eulerAngles;
            pv.RPC("Shoot", RpcTarget.All);
        }
    }

    private bool Shootable
        {
            get
            {
                return true;
            }
        }

    }

Comments