Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411421 Posts in 69363 Topics- by 58416 Members - Latest Member: timothy feriandy

April 18, 2024, 02:08:19 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)How to Create Spawn Prefab in Random Location?
Pages: [1]
Print
Author Topic: How to Create Spawn Prefab in Random Location?  (Read 2204 times)
ArtInkStudios
Level 0
**


Art Ink Studio Logo


View Profile WWW
« on: September 19, 2021, 02:19:56 AM »

We are creating a 2-D vector assets with a fade-in animation that flash multi-colors. But the tricks is that we tried to create a Unity C# script into having the prefab to spawn 15 times in a different location in front of the Earth to where each prefab would appear 2 seconds and only start appearing for every 20 seconds on the timer of the game. The question is that how to create a C# script for Unity to spawning a prefab in a different location, but do not spawn in the same location after the last 15 asset that spawn. It will be a big help, and thank you.

Logged
Attila0413
Level 1
*



View Profile WWW
« Reply #1 on: September 19, 2021, 03:16:22 AM »

You can either randomise the coordinates of the spawn point, or if you want to have more control, just define a few spawn points in the scene, have them in a list and pick one at random, then use its transform position as the prefab spawn position.

Not sure if I understand your last point. If you want to make sure a game object doesn't spawn twice in the same position, you can either cache the last spawn position, or if you use my second approach (predefined spawn points), just mark it as used or remove it from the list when it's selected.
Logged

ArtInkStudios
Level 0
**


Art Ink Studio Logo


View Profile WWW
« Reply #2 on: September 19, 2021, 07:32:31 AM »

Thanks, I'll see to it. As for the second discussion on what I wanted, for example, when the timer reaches 20 seconds as the first 2D asset will fade-in on the left-bottom of the screen before fourteen more 2-D assets are spawn individual within a random location. Then afterward another 20 seconds is reach as the first 2D asset is fade-in on the top-right of the screen as the rest of the fourteen 2D assets is spawn individual in another random location from the last fourteen 2D assets that are random locate at. What we wanted is to keep interchanging the position of the 2D assets for every 20 seconds on the timer before reaching zero to maintain a sense of variety to the challenge. I hope it clears the misunderstanding.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic