• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Musamasilela · Aug 25, 2020 at 12:48 AM · randomspawningendless

Objects move down from top of screen,I want objects to randomly spawn at the top

hey guys i need help with something. I want object to spawn at random positions at the top of the screen and move down to the bottom but sometimes randomly change lanes instead of going down in one direction. ,Hey guys I need help with something... I want different objects to spawn at the top of the screen and move towards the bottom of the screen and randomly change directions instead of moving straight down.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image highpockets · Aug 24, 2020 at 09:41 PM 0
Share

Where is your code? Try to code it, if you don’t know where to begin, I suggest tutorials.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by logicandchaos · Aug 26, 2020 at 12:27 AM

use Random.Range to generate random numbers, you can use them for spawn locations and for moving too. you can make a random number from -1 to 1 so -1 makes it go left down, 0 straight down, 1 right down. or whatever you need.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Llama_w_2Ls · Aug 26, 2020 at 09:34 AM

So basically like...

 public GameObject CubeToSpawn;
 int RandomX;
 
 void Update()
 {
      GameObject spawnedCube = Instantiate(CubeToSpawn, new Vector3(RandomX, 6, 0), Quaternion.identity);
      StartCoroutine(Delay());
 }
 
 IEnumerator Delay()
 {
      yield return new WaitForSeconds(1);
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Llama_w_2Ls · Aug 26, 2020 at 09:35 AM 0
Share

And in the update() sorry i missed to write at the beginning RandomX = UnityEngine.Random.Range(-2, 2)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

133 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with Auto instantiating in X seconds in C# 1 Answer

how to generate custom procedural terrain ? 0 Answers

Instantiate random prefab from folder using Resources.LoadAll 2 Answers

how to increase the radius of Random.insideUnitSphere,how do i increase the range of Random.insideUnitSphere? 2 Answers

Can't get game objects to instantiate at random positions without overlap - please help! 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges