- Home /
Endless Staircase
Hey people, I want to make a 3D Video Game in which a Object go the Stairs up.
But my Problem now is that i don’t know how i can make these stairs in the same order endless as in the picture. Also when i’m going up the Stairs behind me have to deleted byself. I hope anybody can help me. I really don’t know how the Script have to look.
Answer by Klarax · Feb 10, 2020 at 09:42 AM
make the stairs, or any number of variations of the stairs you want.
put an empty gameobect at the top center where the next stair would spawn.
create a script that generates random prefab of a stair at the empty node location.
make sense?
i‘ll try it thx. but do i have to put the first order in one folder and the following order in a other folder that i can say in my script that he have to generate a random folder?
Folders don't come into it.
$$anonymous$$larax's ter$$anonymous$$ology is slightly confusing. You only actually need one prefab - of a single stair (it could have multiple stairs if you want a larger unit, the procedure would be the same).
That prefab could contain 2 empty gameobject children - one that's in the position that the stair above should be placed, and one that's in the position that the stair below should be placed. It would have a "Stair" script on it with fields like "public Transform abovePosition" and "public Transform below position" to give you easy access to those gameobjects' positions.
Then, you start your staircase by creating an instance of that prefab.
Subsequently, you can extend your staircase upwards by instantiating the prefab again, and placing that new instance at the position of the top stair's "above position" gameobject.
Or you can extend it downwards by instantiating the prefab again, and placing that new instance at the position of the bottom stair's "below position" gameobject.
Similarly, you could remove stairs from the top/bottom by destroying them as required.
You don't actually need those 2 "positioning" gameobjects - you could just store the relative pose of the above/below stairs - but doing it by using gameobjects in the prefab makes it easy to tweak the positions.
You'd need some way of getting hold of references to the top or bottom stair. Depending on what your requirements are, you could do this
with a "Staircase" object which is responsible for the whole thing, keeping references to the stairs in a List, adding to the start or end of the List as it creates new stairs (or removing from the List as it destroys them)
or
by giving all the responsibility to the "Stair" class on the stair prefab, which would be responsible for keep track of references to the above/below stairs, and creating/destroying them as required (effectively treating the staircase as a "linked list" of stairs)
$$anonymous$$y recommendation would be to start by getting something like that working, and then think about how to randomly pick from a list of different stair prefabs ins$$anonymous$$d of always using the same one. They could all use the same stair script.
Your answer
Follow this Question
Related Questions
How to destroy a script on loadlevel? 1 Answer
Jump on Enemy heads to destroy enemy? 1 Answer
Character won't jump. 0 Answers
How to change the BoxCollider 2D Xoffset and Y offset by script ? 2 Answers