Instantiate a random item at a random position

Hey people!

I’ve created an array of food items and added them into the inspector, same thing for food spawn positions. I then randomly generated a number between 0 and however long the array is. However, when I try to do network.instantiate I get (on the instantiate line).

BCE0017: The best overload for the method 'UnityEngine.Network.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion, int)' is not compatible with the argument list '(UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.Quaternion, int)'.

How would one go about getting this script to work?

enter code herevar foodSpawnPositions : Transform[];

var foodItems : GameObject[];

var foodToSpawn : float;
var foodPosition : float;

function Start (){

	spawnFood ();

}

function spawnFood () {

	foodToSpawn = Random.Range(0, foodItems.Length - 1);
	Debug.Log(foodItems.Length);
	
	foodPosition = Random.Range(0, foodSpawnPositions.Length - 1);
	Debug.Log(foodSpawnPositions.Length);
	
	Network.Instantiate(foodItems[foodToSpawn], foodSpawnPositions[foodPosition], transform.rotation, 0);

}

Thanks for taking a look!

replace

Network.Instantiate(foodItems[foodToSpawn], foodSpawnPositions[foodPosition], transform.rotation, 0);

with

Network.Instantiate(foodItems[foodToSpawn], foodSpawnPositions[foodPosition].position, transform.rotation, 0);

you try to pass transform instead of vector3 to input on instantiate method (second parameter)