- Home /
I am working on temple run like game
I am working on temple run like game using this Kit. Ruin Run. I want to insert a room with two doors , when my player enters in the room it stops running and user can control with arrow keys , and when it leaves the room by back door it starts running again . what should i do when it collides with the door coliders ?
Answer by Fornoreason1000 · Jan 27, 2014 at 09:08 AM
I'm not using the kit but i could provide some information on how to go about it. It won't be simple but first.
Collision of the First Door
Well when the player goes through the first door, you want to stop calling what ever is making your character run automatically. the character should stop , his animation might not , so you will have to fix that. this can be done by using an if block will a bool as a switch. the switch is triggered by the OnCollisionEnter Command called by Monobehaviour.
then you need to provide some movement logic for your inputs. do you want the character to walk or Run? you could even get the automatic run code to respond to the inputs of the user using events. this can e done many ways its really up to you.
of course you may want to close the first door after the character walks inside so they do not walk out unless you are intending this of course.
Actual movement of the character being implemented depends largely on the code that makes the character run. Of course you can add your own movement script that activates when you collide with the door. you want it to respond to your Arrow keys using the Input classes.
Collision of the Back door
Door Open and you set the switch bool to true, the character will run again like normal.
Door will close behind the character for visuals
Hope it helps.
There is a problem. I am doing this by replacing the scenes. I am instantiating an empty Game-object prefab in GamePlayScene when player is colliding with that i am loading HouseScene and when it is colliding with back door (in HouseScene) i am loading GamePlayScene. but the game is starting from the beginning. how can I resume the game From where I left And keep the track of Distance covered and coins collected? And also for HouseScene . Remember the points i achieved in it. script help would be great. Thanks.
You can make a cache of your position, coins ,points, pickup's and whatever that gets carried over when you collide with GamePlayScene. then load them in to your game. pretty simple really. i thought you were going to instantiate the house on the fly is all.
To make a cache in unity is a bit different from how you would go about it. there more play on $$anonymous$$onobehaviours. you can make one on your manager script (a manager script is a script attached to a game object that Never gets destroyed, even loaded scenes, setting one up is self-explainitory). since that should always be present and will automatically be carried over.
also in future reference, you question is rather vague which can lead to complications from people making assumptions. and the title should be more specific. such as "Inserting a room in a Temple run type game". this will give other users a better description and are more likely to help you.
O$$anonymous$$ @Fornoreason1000 . Thanks for your answer. I will take care of that (Title) in future.