Need Help with Picking Up items Script!

Everything works except it says there is " Object reference not set to instance of an object" error on line 33.
I dont know why this is since in the other script, wood is an integer value. Its the line that says inventory.wood++;

(Someone said inventory was null but i dont really understand why there is a problem)

using UnityEngine;
using System.Collections;

public class RayCollect : MonoBehaviour {

public int rayLength = 10;
bool showGUI = false;
Inventory inventory;

// Use this for initialization
void Start () {

inventory = GameObject.Find(“First Person Controller”).GetComponent();

}

// Update is called once per frame
void Update () {
RaycastHit hitInfo;
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0f));

if(Physics.Raycast(ray, out hitInfo, rayLength))
{

if(hitInfo.collider.gameObject.tag == “Logs”)
{
showGUI = true;

if(Input.GetKeyDown(“e”))
{
inventory.wood++;
Destroy(hitInfo.collider.gameObject);
showGUI = false;
}
}
else{
showGUI = false;
}

}
}

void OnGUI()
{
if (showGUI == true)
{

GUI.Box(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 100, 20), “Pick Up”);

}

}
}

duplicating the thread isn’t exactly helpful either…

when you paste code into the forums please use [ code] [/ code] tags so it is formatted and readable (sticky at the top of the scripting section on those) it also puts in line numbers so we could see which line is 33…

also, if you’re just starting out with unity I would advise learning the new UI system that came in the recent releases rather than the old OnGUI method… it’s alot easier and more powerful.

you can’t access the variable of something that doesn’t exist, because it doesn’t exist.
If “inventory” is null, it doesn’t exist… so how do you increment the wood value of something that doesn’t exist? … you can’t.

add in

Debug.Log(inventory);

after you set the inventory in the start function to check what that line is returning.