Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Dec 26, 2015 at 11:49 AM by Banana13 for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Banana13 · Dec 26, 2015 at 12:21 AM · c#levelgenerationadd

Level Generator porblem

Im making a game where the player has to climb up cubes, the Level generator generates 40 pieces at the start and I want it to add 20 every time the player reaches 20 more. So if hes at the 20 cubes 20 more spawn if hes at the 40 cubes 20 more spawn ...

I have a function to spawn 20 cubes, I only need to make a script that checks if the player reached 20 cubes and then call the spawn function MakeLevel(); once.

Comment
Add comment · Show 2
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 allenallenallen · Dec 26, 2015 at 04:47 AM 0
Share

You're not telling us much. Where are the cubes placed? Is this a 3D game?

Without those details, we can't find a way to detect how many cubes the player has climbed, which I'm sure is the reason you asked this question.

avatar image Zoelovezle · Dec 26, 2015 at 02:13 PM 0
Share

Is that any math question from school? YOu should provide more detail about it as allenallenallen said

1 Reply

  • Sort: 
avatar image
1

Answer by malkere · Dec 26, 2015 at 05:31 AM

allenallenallen is right in that we kinda need more than that.... but, are you jumping up on the y axis? how about if the player.transform.position is equal or greater than 20 you call MakeLevel() ?

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 Banana13 · Dec 26, 2015 at 11:48 AM 0
Share

I figured it out myself, here are the scipts:

Spawns 40 cubes at start:

     private void $$anonymous$$akeLevel() {
         number = UnityEngine.Random.Range (0, colors.Length);
         material.color = colors[number];
 
         for(int i = 0; i < 40; i++) {
 
 
 
             if(i == amountToSpawn - 1) {
                 g = Instantiate<GameObject>(endPlatformPrefab);
             } else if(i == 0) {
                 g = Instantiate<GameObject>(startPlatform);
             } else {
                 g = Instantiate<GameObject>(platformPrefab);
             }
 
             g.transform.parent = transform;
             spawnedBlocks.Add(g);
             if(i == 0) {
                 lastPos = g.transform.position;
                 continue;
             } 
 
             if(i < amountToSpawn) {
                 if(g.GetComponent<Platform>() != null && i != amountToSpawn - 1) {
 
                     float chanceOfObstacle = 1f;
 
                     if(i > 20) {
                         chanceOfObstacle = 0.75f; // 20%
                     } 
                     if(i > 40) {
                         chanceOfObstacle = 0.6f;
                     } 
                     if(i > 60) {
                         chanceOfObstacle = 0.5f;
                     } 
                     if(i > 80) {
                         chanceOfObstacle = 0.4f;
                     }
                     if(i > 100) {
                         chanceOfObstacle = 0.2f;
                     }
 
                     float c = UnityEngine.Random.value;
                     if(c > chanceOfObstacle) {
                         g.GetComponent<Platform>().EnabledAsObstacle();
                     }
 
 
                 }
             }
 
             int left = UnityEngine.Random.Range(0, 2);
             if(left == 1) {
                 g.transform.position = new Vector3(lastPos.x - blockWidth, lastPos.y + blockHeight, lastPos.z);
             } else {
                 g.transform.position = new Vector3(lastPos.x, lastPos.y + blockHeight, lastPos.z + blockWidth);
             }
 
             lastPos = g.transform.position;
 
             }
 
         }
     }

$$anonymous$$akes a new cube spawn when the player gets higher:

     private void PopupStep(EventObject evt) {
         steps++;
         score.text = steps.ToString();
         levelgenerator.$$anonymous$$akeLevel2();
     }

$$anonymous$$akeLevel2 just spawns one new cube.

Follow this Question

Answers Answers and Comments

48 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Strange random seed issue with level generation 1 Answer

How can I end a level and go to the next level 1 Answer

How to use Hashtables? 0 Answers


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