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”);
}
}
}