T
T
Taisu Black2020-05-11 22:56:54
2D
Taisu Black, 2020-05-11 22:56:54

I'm making a 2d space shooter how to spawn objects that will spawn in random places?

5eb9ad98a230c657250315.pngThere is a blue block, this is a spawner, I want meteorites to randomly spawn for my 2d game, please tell me how this can be done? I will be very grateful)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Garbazhiy, 2020-05-12
@UnityEngineDanil

I think you are doing this project for study. Then it will be more useful if you think for yourself.
To make it easier, I will give you a few scripts from the piggy bank of experience)
Timer

public float interval;
private float timer;

void Update()
    {
        timer -= Time.deltaTime;

        if (timer <= 0)
        {
        	timer = interval;
                // делаем что-то
        }
    }

Create object
public GameObject toSpawn;

void Start()  //start не принципиально, можно использовать любой другой нужный вам метод
    {
        Instantiate(toSpawn, *position*);    // * не писать, просто позиция в формате Transform
    }

Random
Random(min, max);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question