- Home /
Want 3 different Random Platforms in x direction
I have 3 different platforms of various size
Platform one = 1 unit in size
platform two = 2 units in size
Platform one = 3 units in size
I want them to be generated in random order in X direction endlessly with random space (5-8 units) in between them.
Can anyone Help me
Answer by dmitriy-untilov · Feb 19, 2018 at 02:09 PM
Idea described in following pseudocode:
var Platforms; //platform prefabs
var startingPoint = vector3.zero
in Update function:
Select Random platform from Platforms array and make Instance of prefab
var space = random(5,8)
platform.position = startingPoint
startingPoint += platform.size + space //next position
Also you can optimize this algorithm. You can make a pool of predefined platforms and when some platform goes out of the camera you can swap platform`s position instead of using Instantiation each time.
You didn't get what you expected because you expected the final code you want to implement. @dmitriy-untilov has showed you the way in pseudocode, and you should translate that to code. If you can't translate pseudo code to code I strongly recommend you watching all the official scripting tutorials from Unity's webpage. You can find them here: https://unity3d.com/es/learn/tutorials/s/scripting
Unity Answers is to submit doubts or issues and try to solve problems, not to tell what you want and expect someone to write down all the code.
Regards.
I want the player to jump 2 time if I press any key 2 times & jump 3 time if I press any key 3 times. And other input should not work until the player complete 2 jumps if I press any key 2 times.
How can I do it.
To implement jumping you need to add Rigidbody2D component to your character and use rigidbody2D.AddForce(new Vector2(0, 10), Force$$anonymous$$ode2D.Impulse);