- Home /
Instantiating prefab at child (spawnlocations are arrays)
Hi,
I want to instantiate an object at one of my children.
So I've listed all my children in an array like this one: var array : Transform [] = new Transform[blabla];
Than I've put my children in the array like this: array[i] = transform.Find("All of my Children");
Don't mind the details on how I did this, it worked, and I've tested the children like this: array[0].Translate(Vector3.right);
The child was moving so it's in the array for sure;)
But now I want to instantiate a prefab at the position my children has (they are actually spawnpoints).
If I use this: Instantiate(prefab, array[0], Quaternion.identity);
it gives me an error:
Assets/Scripts/Game/SpawnLeft.js(30,20): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Transform, UnityEngine.Transform, UnityEngine.Quaternion)' was found.
So why is this not an appropriate version? The array is of type Transform.. so what's wrong?
Answer by Anxo · Jun 13, 2011 at 02:55 PM
you want to instantiate a gameobject, and your second entry is not a position but a transform.
Instantiate(gameObject, position, rotation) you are doing Instantiate(transform,transform,rotation);
when you get an error like that you can always check documentation for Instantiate and see that your argument list does not match the listed list under instantiate http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
Answer by Quantum · Jun 13, 2011 at 03:02 PM
Thanks for the quick reply!
array[0].position works! =D
And I'll pay more attention the next time!
Your answer
Follow this Question
Related Questions
Multiple random spawns from an array 1 Answer
Spawning Objects Using An Array. 1 Answer
add spawned GameObjects in an array C# 1 Answer
onTrigger spawn object C# 3 Answers
Spawn from array 2 Answers