Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 SCharilaou · Mar 06, 2013 at 12:45 AM · randomobjectsappear

Objects appear randomly in specific length and height

My character will be blast off from a catapult. It will bounce until it stops (speed = 0). In the meanwhile there will be objects in the sky or ground that if the character hit them they will increase it's speed or slow it. My question is, how can i make this objects appear randomly at all length that is e.g 50,000 meters(and height for the sky objects e.g 1,000 meters)? And what troubles me is that in level 1, one of the objects number of appearance will be 40% and on level 2 will be 60%. How do i do that? I am new in unity and i'm confused with the scripting part. Thank you in advance!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · Mar 06, 2013 at 08:36 AM

This code creates GameObject primitives at random locations around the origin bounding by minimum/maximum X, Y, & Z values. Attach it to an empty game object:

 var minX = -10.0;
 var maxX = 10.0;
 var minZ = 5.0f;
 var maxZ = 35.0f;
 var minY = -2.0f;
 var maxY = 7.0f;
 
 function Start () {
     for (var  i = 0; i < 300; i++) {
         var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
         go.transform.position = Vector3(Random.Range(minX, maxX), Random.Range(minY, maxY), Random.Range(minZ,maxZ));
     }
 }
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 Maulik2208 · Mar 06, 2013 at 09:52 AM 0
Share

Upvoted =) @robertbu has suggested a good way....by using Primitive you can have many objects in optimum draw calls and by the Random.range you can place the objects randomly......enjoy

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.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Instantiate Random Object at Random Position 1 Answer

Generating objects randomly, only one will Instantiate 0 Answers

How do I make an object appear differently to different players? 2 Answers

Beginner : Random gameobject from array 2 Answers

How to random between 2 objects while spawning? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges