Item pickup add to inventory?

I’ve spent the entire day trying to figure this out to no avail. I have created a script for a simple inventory and I am trying to make the item I want the player to be able to pick up add to the inventory. Its a really simple text inventory but it doesn’t seem to work. Here’s the code for the inventory:

#pragma strict

var showGUI : boolean = false;
var woodInv : int;

woodInv = woodPickup.woodInvAmount;

function Update () 
{
	if (Input.GetKeyDown(KeyCode.F))
		{
		if(showGUI == false)
		{
			showGUI = true;
			Debug.Log("showGUI = true");
		} else{
			showGUI = false;
			Debug.Log("showGUI = false");
		}
	}
}

function OnGUI()
{
	if(showGUI == true)
	{
		GUI.Box (Rect (10,10,100,90), "Inventory");
		GUI.Label (Rect (15,35,40,30), "Wood:");
		GUI.Label (Rect (75,35,40,30), " " + woodInv);
	}
}

And here is the code for the wood pickup item:

#pragma strict
static var woodInvAmount : int = 0;

function OnTriggerEnter (Col : Collider) 
{
	if(Col.tag == "Player")
	{
		++woodInvAmount;
		Destroy(gameObject);
	}
}

Any Help would be very much appreciated!

*P.S. This is in UnityScript

@richyrich has the problem right. Change line 29 to:

GUI.Label (Rect (75,35,40,30), " " + woodPickup.woodInvAmount);

Note that you are heading down a dangerous path using static variables this way. Some deep thinking about your desired structure is probably warranted.

It looks like your woodInvAmount is being set initially but never updated so only the initial value of 0 will be used.

A quick fix would be to move the line “woodInv = woodPickup.woodInvAmount;” into the update function.

If it were me I would add a function to the Inventory script called “WoodPickup” or something and pass the woodInvAmount as a parameter, the passed in value could then be added to the private WoodInv integer and displayed.

You could then reference this script from within your Wood Pickup Item script and call the function before destroying the object.

Good Luck!