help with pickup script

I am using the following script to destroy a GameObject when the player picks up all of the pickups in a level. Each pickup is tagged with a ‘Pickup’ tag, and when all of the objects with that tag are gone, the GameObject should be destroyed. But it is not destroyed by the script! What should I do to the folowing script to make it work?

I also get the following errors (as seen in the image)

// FuelExist.js
function Update () {
	var fuel = GameObject.FindWithTag("Fuel");
	// Is the below line the right way to check if any object with the tag exists?
	if (fuel.transform.FindWithTag) false;
	var go = GameObject.Find("impoundFence");
	// Is this the right syntax to destroy the above object?
	 Destroy ("impoundFence");
	 	}

I would have a count variable and set it to zero. Then every time you pickup an item, increment the count variable. When the count variable reaches the amount of items on the level, then destroy the object.

As for your errors:
if (fuel.transform.FindWithTag) false; I think this line is incorrect, not really sure what you are trying to do.

Destroy (“impoundFence”); I’m 99% sure you can’t just type in the name of the object, I thought you had to declare it as a variable.

I’m not sure what you’re trying to do with if (fuel.transform.FindWithTag) false; since you don’t seem to be doing anything with it and are treating FindWithTag as a variable. If you’re looking to see if there’s an object tagged “Fuel,” and you’ve tried to find it using FindWithTag, you can simply ask

if (fuel) { 
    //consequent
} else {
    //alternative
}

as described in the documentation here. As for destroying “impoundFence,” I might go with something like the following after the line where you Find() it:

if (go) {
    GameObject.Destroy(go);
}

Okay, so I have changed the script a bit.

I still get an error: BCE0034 Expressions in statements must only be executed for their side effects.

What does this mean and how do I fix it?

// FuelExist.js
// This script checks to see if any GameObjects tagged Fuel exist.
// If not, destroy the parent GameObject 
function Update () {
	var fuel = GameObject.FindWithTag("Fuel");
	if ("Fuel")
		var foo = 0;
	else
		GameObject.Destroy;
	}

The error you’re getting is because of this line:[quote=“”]

GameObject.Destroy;

[/quote]
Destroy is a function. Referring to it without the parentheses at the end means you’re using it as a variable (which you can do for delegates and such, but that’s beyond the scope of this thread) and not actually calling it. If you want to destroy the GO the script is attached to, you would call GameObject.Destroy(gameObject)While I’m at it, what are you doing here:[quote=“”]

var fuel = GameObject.FindWithTag("Fuel");
	if ("Fuel")

[/quote]
Did you mean if (fuel)? Otherwise, you’re asking if the string “Fuel” exists, which it does. Always and forever.

If I take away the quotes I get this error:

BCE0005 Unknown identifier ‘Fuel’

Unity’s scripting language is case sensitive. You must type the variable name exactly as you declared it (that is, with a lowercase “F”). If you use the test as I wrote it, it should work.