- Home /
Instantiating multiple prefabs with animations all appear at 0,0,0
Hi
I was wondering if anyone had any insight into my problem.
I've created a prefab of a 2d wave with a simple animation attached. I want to create a number of them in a row to create a curtain along the bottom of my screen, however they all appear at the center of the world, rather than the position along the X axis that I specify...
My simple enough code is:
var seaPrefab : GameObject; var counter: int = 0; var depthVariable: int = 0.2;
function Update () {
if(Input.GetAxis("Horizontal")){
var seaLayerInstance : GameObject = Instantiate(seaPrefab, Vector3(counter*2, 0, depthVariable), transform.rotation);
counter++;
depthVariable *= -1;
};
};
I've also put my animated prefab inside an empty GO hoping to offset the prefabs that way, but that has also not worked.
Any help would be greatly appreciated!!
Cheers,
Rob
Answer by RaptopLob · May 20, 2011 at 01:07 PM
The problem was I wasn't using the prefab as a child of an empty GO as I had attempted to do.
Answer by Jeston · May 12, 2011 at 08:41 PM
Check the inspector to make sure your world units are far enough apart. Have you tried something like:
seaLayerInstance.transform.position = Vector3(....);
Answer by Owen-Reynolds · May 12, 2011 at 11:51 PM
Input.GetAxis("Horizontal")
does not allow you to pick a position. It is always between -1 and 1, and represents how long you have been holding down Left/Right arrow (1 means you've held Right-arrow long enough to be sliding or turning at full speed.) It's for moving the player.
This Unity doc has an example of making a wall, in Start. Could adapt it for your line: http://unity3d.com/support/documentation/Manual/Instantiating%20Prefabs.html
Also, depthVariable should be a float (since you're using 0.2.)