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 rodude123 · Jan 01, 2014 at 12:50 AM · 2d-platformerendless runner

how t make a random number generator for a 2d endless side scroller

I have tried for so long and I have got this far to figure this much out can any one help me using the script that I provide public class PlatformManager : MonoBehaviour { public int startingNumber; public List<string> levelComponents; 5. // define it as the height on one or more component objects (The actual value you will need to find out) public float componentBuffer; public float screenBuffer; public List<Transform> platformList; 10. private Vector3 nextPosition; private Transform player; void Start() { 15. nextPosition = new Vector3(0.0f, -componentBuffer, 0.0f); platformList = new List<Transform>(); for (int i = 0; i < startingNumber; i++) { int randComponent = Random.Range(0, levelComponents.Count); 20. GameObject newPlatform = PoolManager.Spawn(levelComponents[randComponent]); newPlatform.transform.position = nextPosition; platformList.Add(newPlatform.transform); nextPosition.y -= componentBuffer; } 25. } void Update() { if (player == null) 30. { player = GameObject.Find("Player(Clone)").transform; } else { 35. if (nextPosition.y > player.position.y - screenBuffer) { int randComponent = Random.Range(0, levelComponents.Count); GameObject newPlatform = PoolManager.Spawn(levelComponents[randComponent]); newPlatform.transform.position = nextPosition; 40. platformList.Add(newPlatform.transform); nextPosition.y -= componentBuffer; } if (platformList[0].position.y > player.position.y + screenBuffer) 45. { PoolManager.Despawn(platformList[0].gameObject); platformList.RemoveAt(0); } } 50. }

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 robertbu · Jan 01, 2014 at 02:18 AM 1
Share

Your code is unreadable, and since you clicked on the wrong button, I cannot fix it for you. You need to:

  • Edit your question by clicking on 'edit'

  • Delete your existing code in the question

  • Past a new copy of your code into the question

  • Select your code

  • Click on the 101/010 button to format your code.

avatar image rodude123 · Jan 01, 2014 at 10:57 AM 0
Share

thanks for telling me

1 Reply

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

Answer by reefwirrax · Jan 01, 2014 at 11:06 AM

you get random numbers from Random.Range and PerlinNoise in Unity.

if you make the random number a function of position/pixels, you do (perlin noise((x+y float, seed)*500 )+x) %1= different float between 0 and 1 for every 2d point in space. the plus x at the end stops perlin from having a bell curve and makes it linear.

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

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

20 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

Related Questions

Want 3 different Random Platforms in x direction 1 Answer

2D side scroller/flappy bird clone 0 Answers

How do you hang on to a ledge in a 2d game 1 Answer

How do I attach a script to a state 1 Answer

C# 2D Jumping with AddForce doesnt work 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