- Home /
Two player collision ?
I have two players. Each have rigid bodys (just saying) i need a global script that detects their collision with eachother/when they collide with the other.
and sends them to the next level in the build.
its not just application.loadlevel ("nextlevel") that would take a bunch of different unique scripts which i dont need.
I need a way for the players to keep advancing to the next level everytime they collide with eachother. There are going to be multiple levels/scenes
ex: Player1 collides with Player2 loadlevel "level 2" Player1 collides with player2 on level 2, "loadlevel 3" so on and so forth.
any suggestions would help.
Thanks
Answer by MaGuSware™ · Dec 23, 2012 at 11:18 AM
For loading your levels you will have to make sure they are indexed correctly. You can use "Application.LoadLevel(Application.loadedLevel + 1);" which will load your next indexed level.
As for the collision, does it have to be a global script? I assume you are worried about the level loading being called twice. That should not be a problem, you can change the tag of the players to something other than "Player" when they have collided. That way when the other collision function runs, it won't pass the tag check and the level load function will not be called again. When the level is loaded the players will be reset anyway right? If not you can always add the OnLevelWasLoaded function to the script and set the player tag back to "Player" manually.
I think i was using "global" wrong. (also thanks for the loadlevel help) But now everything is working just dandy,all i needed was +1. Literally feel like an idiot. but mucho thanks to you.
Your answer
Follow this Question
Related Questions
Load Level on Collision 1 Answer
Loading Level Async without switching the level immediately 5 Answers
Mesh separating from CharacterController 0 Answers
How to turn of collision for the player 1 Answer
Collision not working after Loadlevel 0 Answers