Level Change on Collision with wrapping
I have a large set of levels. I am trying to implement them in a 10x10x10 grid arrangement. If the player goes right and hits the collider, it takes them to the current level +1.
Works great, until for some reason, when the player gets to level 7 and hits the collider, it takes them back to the start. That would be cool, if that happened in level 9! in Start I have set the variable curScene = SceneManager.GetActiveScene().buildIndex; Here is the code:
else if (direction == "right")
{
Debug.Log("Hit right collider");
int ones = curScene % 10;
int tens = curScene % 100 - ones;
int hundreds = curScene % 1000 - tens - ones;
int thousands = curScene % 10000 - hundreds - tens - ones;
if (ones == 9)
{
destinationScene = curScene -= 9;
}
else
{
destinationScene = curScene += 1;
}
Debug.Log("destination is " + destinationScene);
playerShip.transform.position = new Vector3(5000, 0, 0);
playerShip.transform.rotation = Quaternion.Euler(new Vector3(0, -90, 0));
}
I will need to do this for Left, Front, Back, Up and Down. I sure would like to get one direction working. Any ideas why it might be doing this? Mark
Answer by Mad_Mark · Apr 14, 2018 at 11:33 PM
Solved. Forget to account for the 2 additional scenes in the build index. CurScene uses the build index to track the current scene. DOH!
Your answer
![](https://koobas.hobune.stream/wayback/20220612160726im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Main Menu Help 2 Answers
Safe Timer Score when changing scenes 0 Answers
Guys please help me with this SceneManager in Unity 5 1 Answer
Problem with switching from a certain scene 0 Answers
C# scripts not showing up in scene... please help! 0 Answers