- Home /
How can I position an instantiated row of prefabs?
Hi, I've instantiated a row of prefabs, but I'm not able to change their position. I'd like them higher, but they appear at the middle of the screen. I've tried to manipulate the position in the instantiate section, but that does nothing. And when I change the local position, it only moves them apart. Thanks!
public Transform pointPrefab;
void Awake()
{
for (int i = 0; i < 10; i++) {
Transform point = Instantiate(pointPrefab, new Vector3(-20, 1, 0), Quaternion.identity);
point.localPosition = new Vector3(1, 0, 0) * i;
}
}
Try playing with y value ins$$anonymous$$d of x. Set y value higher like new Vector3(-20, 5, 0)
for instance.
Answer by surfuay · Apr 03, 2019 at 04:30 AM
if this set of prefabs are children, you could just call it as
Instantiate(pointPrefab, transform.position + new Vector3(x, y, 0) (this would be however offset the parent you want it), quaternion.identity); and that would just be set where ever you're tyring to call it in game.
if this is happening as soon as you start the game then just set the position in the start or awake method as
transform.position = new Vector3(x, y, 0);
Your answer
Follow this Question
Related Questions
Wrong particle and prefab spawn position 1 Answer
Prefab not instatiating at correct position 1 Answer
Stop Children of Instantiated Parent From Offsetting After Changing Position 0 Answers
prefab always instantiates at 0.0.0 1 Answer
Setting the parent of a transform which resides in a prefab error 1 Answer