0

In Unity, I am getting the following error:

NullReferenceException: Object reference not set to an instance of an object Burrow.OnMouseDown () (at Assets/Angry Birds Style/Scripts/Burrow.cs:16) UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

When I try to run this script:

using UnityEngine;
using System.Collections;

public class Burrow : MonoBehaviour {

    void Start () {

    }

    void Update () {

    }

    void OnMouseDown() {
        if (!GameObject.Find("Projectile").GetComponent<ProjectileDragging>().launch) {
        GameObject.Find("Projectile").GetComponent<ProjectileDragging>().burrow = true;
        }
    }
}

This script is attempting to reference variables from a script from a separate object in Unity.

1 Answers1

0

First off, if at all possible, don't use GameObject.Find(), it's terribly inefficient.

Secondly it's likely that the game object isn't being found, you should check that it is not null first, and then do your operations.

Enfyve
  • 916
  • 10
  • 22