How to make multiple objects spawn at random order and move ?
First of all, I'm an absolute beginner. Following tutorials, I was able to make my object move and spawn. My issue is that i dont know how to make the object only move after spawning. My goal is to make multiple object spawn randomly and move on their own from right to left.
Should the movement script be in the spawn script? As of now, movement script is added to the object and spawn script was added to an empty.
Edit: Finally got the spawn to be the way i want it. Only thing remaining the random spawn of 3 object
Spawn code I'm using:
public class Spawn : MonoBehaviour {
// Spawn variables
public GameObject spawnee;
public bool stopSpawning = false;
public float spawnTime;
public float spawnDelay;
// Use this for initialization
void Start () {
InvokeRepeating("spawnObject", spawnTime, spawnDelay);
}
// Spawn
public void spawnObject()
{
Instantiate(spawnee, transform.position, transform.rotation);
}
}
Answer by Poi7ioN · Apr 19, 2019 at 02:43 PM
public void spawnObject()
{
Instantiate(spawnee, transform.position, transform.rotation);
}
Here Instead of this you can try using random.range
public void spawnObject()
{
Instantiate(spawnee, new Vector3(Random.Range( 0f , 20f ),Random.Range(0f,20f),0f)), transform.rotation);
}
//you can provide the range as per your spawn area
// I've kept z axis zero considering its a 2d game.
Your answer
Follow this Question
Related Questions
how to randomly move each generated clone? 0 Answers
c# Make a object chose a random direction then it moves in that way C# 0 Answers
Spawning enemies using insideUnitCircle : 2 Answers
Picking up an item and spawning a new one. 0 Answers
My sprite looks like it is haveing a seizure. What am I doing wrong? 1 Answer