- Home /
How can I align instantiated prefabs randomly on runtime #C
Hello everybody,
I have followed a tutorial where they were making a infinite runner (I am a biginner with Unity). During this tutorial a Spawner Script was written to instantiate random PreFabs. This script was attached to a Quad which was a child of the Maincamera (It is leading the camera).
However this script was spawning the PreFabs randomly between the 1 and 2 second time range. Because I want aligned panels I am not able to use this code in this way. I have searched for different solutions already but couldn't come to any conclusion.
The PreFab panels are all the same size. The game is vertically orientated. I wish that they are placed randomly.
What should I change to this code to make the panels align with each other?
I really appreciate help or hints as I am a beginner.
Thank you in advance :)
The code they were using:
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public GameObject[] obj;
public float spawnMin = 1f;
public float spawnMax = 2f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Instantiate (obj [Random.Range [0, obj.GetLength(0)], transform.position, Quaternion.identity);
Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
}
}
Your answer
Follow this Question
Related Questions
Spawning Objects Using An Array. 1 Answer
Can't set the random position for an Instance. 1 Answer
How do you instantiate just one prefab? 1 Answer
Object Spawning Randomly 0 Answers