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 Lemo76 · Feb 17, 2013 at 04:09 AM · gameobjectrandomspawn

Fixed Spawn Amount

Ok, so i've got a script which is applied to different object which tells it to spawn cubes when a particle hits the object.

So I've got this script:

 var ThePlace : GameObject;
 var hasportal : boolean;
 var portalblue : GameObject [];
 
 function newportal () {
     
     if (hasportal==false){
     
     theportal=Instantiate(portalblue[(Random.Range(0, portalblue.Length))],ThePlace.transform.position,transform.rotation);
     theportal.transform.eulerAngles.x=-90;
     theportal.transform.position.x=ThePlace.transform.position.x+1;
 }
 }

I want to set it up so that every one in a thousand cubes which spawn, a small cube spawns. (portalblue is the cube, The Place is the place where they spawn, hasportal is if the particle hits the object)

I don't want to go into each object in the Inspector and add 1 thousand elements, 999 being a cube and 1 being a small cube.

How do I set it up in this script so that I can set percentages? Thanks

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
0

Answer by robertbu · Feb 17, 2013 at 05:40 AM

You can do it through absolute count, or you can do it through random number. For count you could have a variable that you increment each time you spawn. And then code something like:

 if (iCount >= 1000)
 {
     iCount = 0;
     // Do the small cube spawn.
 }

For random you could do something like:

 i = Random.Range(0,1000);
 if (i == 0)
   // Do the small cube spawn.

The second method produce small cubes on average every 1000 spawns.

Comment
Add comment · Show 7 · 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 robertbu · Feb 17, 2013 at 06:33 AM 0
Share

I'm confused about your answer. I assumed you want to Instantiate something other than...

     theportal=Instantiate(portalblue[(Random.Range(boxspawn, portalblue.Length))],ThePlace.transform.position,transform.rotation);
 

...every 1000 uses. You would have a variable iCount which you declare at the top of the file and increment every time you do an Instantiate. You code might look something line:

 if (iCount < 1000)
     {
        theportal=Instantiate(portalblue[(Random.Range(boxspawn, portalblue.Length))],ThePlace.transform.position,transform.rotation);
         iCount++;
     }
     else
     {
        // Instantiate the small box;
        iCount = 0;
     }

I may be missing what your are trying to accomplish here. If do add more details and I'll try again.

avatar image Lemo76 · Feb 18, 2013 at 06:47 AM 0
Share

This script:

var ThePlace : GameObject; var hasportal : boolean; var portalblue : GameObject [];

function newportal () {

 if (hasportal==false){
 
 theportal=Instantiate(portalblue[(Random.Range(0, portalblue.Length))],ThePlace.transform.position,transform.rotation);
 theportal.transform.eulerAngles.x=-90;
 theportal.transform.position.x=ThePlace.transform.position.x+1;
 //theportal.transform.eulerAngles.y=270;

}

}

The Random.Range needs to be edited so that 1 in a thousand boxes will spawn the small boxes. How will I accomplish this and it has to be in the if (hasportal==false){ .

Any help will be greatly appreciated. I am slowly creating a game.

avatar image robertbu · Feb 18, 2013 at 03:11 PM 0
Share

What does the Instantiate look like for the small box?

avatar image Lemo76 · Feb 18, 2013 at 08:29 PM 0
Share

I changed the 'small box' into a faulty cube: http://www.youtube.com/watch?v=NbGcIm27Twg As you can see I set a wall to spawn only faulty cubes just to show you what they are like. The Blue boxes you soon see in the video are the main boxes. You could as well say that the faulty cube is more or less an easter egg (Term for a hidden secret) because the gun is textured quite dusty.

avatar image robertbu · Feb 19, 2013 at 01:38 AM 0
Share

Not what I was looking for. I'm trying to understand what the line of code looks like for Instantiating a small box. Anyway putting together the code you posted with what I posted would look like:

 if (hasportal==false){
 
     if (iCount < 1000) {
         theportal=Instantiate(portalblue[(Random.Range(boxspawn, portalblue.Length))],ThePlace.transform.position,transform.rotation);
         iCount++;
  
         theportal=Instantiate(portalblue[(Random.Range(0, portalblue.Length))],ThePlace.transform.position,transform.rotation);
         theportal.transform.eulerAngles.x=-90;
         theportal.transform.position.x=ThePlace.transform.position.x+1;
     }
 else
     {
        // Instantiate code for the small box goes here
        iCount = 0;
     }
 
 }
Show more comments

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

9 People are following this question.

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

Related Questions

Generate random number and set a GameObject active. 1 Answer

Spawn random amount of gameobjects 2 Answers

Spawn game object in random position on screen 1 Answer

Spawn random amount apart of each other 1 Answer

Instantiate Random 3D Objects/platforms that dont overlap 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