- Home /
Opening new level in unity
I am making a car driving game and I was wondering if how I would open a new level once the computer saw that the car was in a certain x, y, and z position? Preferably in c#
there is several question like this. why not searching befor ask here!!
Answer by DecipherOne · Jun 25, 2013 at 10:52 PM
I would place a collider at the said position, once the car collides it, have your statemanager load the next scene/level. This should be fairly trivial to code.
Put a collider on the car or the position you want the car to stop at and write this code onto the object OnCollisionEnter (Collision col) { if(col.gameObject.name == "The Name Of the object that doesnt have the collider") { Application.LoadLeve("The next level scene name"); } } }
Answer by malu · Jun 26, 2013 at 07:54 AM
How about making a simple distance check from your map(level)origin to your car? For example if your car have only 20% distance left to your map border then load the next level or map resources. Log your distance results and read the distance on this specific location... or reading out the map (MeshRenderer)bounds (size) for maxDistance clamp.
// replace the mMapBounds with any other centered Vector3
float distance = Vector3.Distance(mCar.transform.position, mMapBounds.center);
if(distance > z) // z can be a calculated value or set a fixed one
{
Debug.Log(string.Format("Car reached map border threshold. Distance: {0}", distance));
//Resources.Load("");
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Level Joining Issue 1 Answer
Playing a Level-Up Sound 1 Answer