- Home /
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!
Answer by ScroodgeM · Aug 26, 2012 at 06:27 PM
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)
Your answer
Follow this Question
Related Questions
Network.Instantiate only Instantiates on one client. 0 Answers
Network.Instantiate doesn't create player 2 gameobject. 0 Answers
Passing random values to a client. 0 Answers
Network Instantiate error even when connected? 1 Answer
can you instantiate random prefabs from the resource folder? 2 Answers