NullReferenceException on this.photonView.RPC()

Options
Hi, where is the problem? it give me NullReferenceException on this.photonView.RPC().
Code:

public class UploadToNetwork : Photon.MonoBehaviour
{
GameObject canvas;
GameObject timer;
public GameObject timerPrefab;
void Start () {
canvas = GameObject.FindWithTag("Canvas");
}

public void createTimer() {
if (PhotonNetwork.isMasterClient)
{
timer = PhotonNetwork.InstantiateSceneObject("TimerInstance", Vector3.zero, Quaternion.identity, 0, null);
}
this.photonView.RPC("InstantiateTimer", PhotonTargets.All, "Instantiate Timer!");
}

[PunRPC]
void InstantiateTimer(string message)
{
Debug.Log("[RPC] " + message);
timer = (GameObject)Instantiate(timerPrefab, transform.position + transform.forward, transform.rotation);
timer.transform.parent = canvas.transform;
}

Comments