Attaching Prefabs between them
Hello, I'm creating a 3D platformer game. Currently creating a system where it has a list of given prefabs, and generates the path ahead with those prefabs (think stepping stones). I'm currently having difficulty "snapping" the prefabs between them in a line, I want to use empty gameobjects as anchors but I'm not sure how.
Attached is the code worked on I've also read how you can use transform to put it in the pivot position of the parent... not sure how aswell
public GameObject prefab;
public GameObject prefab2;
public GameObject prefab3;
public float gridX = 5f;
public float gridY = 5f;
public float spacing = 2f;
void Start() {
for (int y = 0; y < gridY; y++) {
for (int x = 0; x < gridX; x++) {
Vector3 pos = new Vector3(x, 0, y) * spacing;
Instantiate(prefab, pos, Quaternion.identity);
Instantiate(prefab2, pos, Quaternion.identity);
Instantiate(prefab3, pos, Quaternion.identity);
}
}
}
void other() {
for (int y = 0; y < gridY; y++) {
for (int x = 0; x < gridX; x++) {
Vector3 pos = new Vector3(x, 0, y) * spacing;
Instantiate(prefab2, pos, Quaternion.identity);
}
}
}
Your answer
Follow this Question
Related Questions
Making Prefabs with new origin from imported model? 0 Answers
Accessing custom pivot through script 0 Answers
RectTransform Pivot versus the Blue Dot. 0 Answers
Object transform rotation around correct pivot, but wrong pivot after colliding 0 Answers
Is it possible to rotate a gameobject along two or more axis using animation editor? 0 Answers