How to pass a game object through to a function?

I am looking to create a general script that will spawn the game object passed to it within the play area as required. However I am receiving the error that “‘spawn’ takes 0 arguments”. The GameObjects are all declared at the top of the script, (e.g. public GameObject food;) and I am sending them to this function with a line like this in the update section:

	if	(GlobalVars.foodToSpawn > 0 ) 
	{
		spawn(food);
		GlobalVars.foodToSpawn -= 1;
		print ("Food to spawn: " + GlobalVars.foodToSpawn);
	}

Below, the spawn function looks like this:

void spawn(GameObject thing)
{
	float x = Random.Range (playAreaMinX, playAreaMaxX);
	float z = Random.Range (playAreaMinZ, playAreaMaxZ);
	Instantiate(thing, new Vector3 (x, 0, z), transform.rotation);
}

This is presumably the wrong way to send a game object to a function as a variable, but I don’t know why.

Clearly your function declaration and call is correct. There must be another spawn() function in the scope, that gets called. Try changing the name to spawn2 or something. If that helps, figure out why the wrong spawn is in the scope.

For future reference I ended up using the function just to get the random variables, and then instantiating using that variable. As a result I don’t know if it would have helped to change the name of the function.