NullReferenceException: Object reference not set to an instance of an object

Well, after searching the Internet for this answer, I can not figure out how this is happening. I have seen forums discussing that you need to Instantiate the object, but I can not get my head wrapped around what the code needs to look like.
The idea is this: The player wants to launch a UAV (drone), and see the camera, that is on the drone, displayed on the monitor he is looking at, on the table, so that he can fly the drone around...
This is what I have at this point


<br /> using System.Collections; using System.Collections.Generic; using UnityEngine; public class DroneMonitor_Trigger_Script : Photon.MonoBehaviour { public GameObject Drone; public float Speed; public bool HaveWeEnteredTrigger = false; public Vector3 dir; //========================================================================= [PunRPC] public void MoveDrone(Vector3 direction) { Drone.transform.Translate(Vector3.up * Time.deltaTime * Speed); } //========================================================================= public void OnTriggerEnter(Collider other) { if(other.tag == "Player") { HaveWeEnteredTrigger = true; } } //========================================================================= // Update is called once per frame void Update () { if (Input.GetKey(KeyCode.Insert)) { if (HaveWeEnteredTrigger == true) { dir = Vector3.up; photonView.RPC("MoveDrone", PhotonTargets.MasterClient, dir); // The above line is what is generating the error... // NULLREFERENCEEXCEPTION: Object reference not set to an instance of an object. // DroneMonitor_Trigger_Script.Update() (at Assets/DroneMonitor_Trigger_Script.cs:39) } } <img src="http://www.carpatheous.com/DroneWithCamera.png" alt="" /> } }

Comments

  • RobertB
    RobertB
    edited May 2018
    Why does this not post the code in a formatted way? I used the but it does not format it correctly. What is wrong with this website?
  • Hi @RobertB,

    do you have an actual reference to the attached PhotonView component? You can do this for example in the Awake or Start function by using photonView = GetComponent<PhotonView>();.