Question by
JacobDement · Sep 14, 2016 at 06:11 AM ·
scripting problemscripting beginner
How to collide to the next level
I want to make a simple game (for my first game but I want to collide in order to go to the next level I'm very confused on the script I should use or how to implement it I know C sharp basics and that's it, comment how I would go about doing this
Comment
Answer by lloladin · Sep 14, 2016 at 09:56 AM
so you want a object with a collider, like once the "player" enters the collider load next level in that case you can do something like this "not tested code"
// and this checks if your object collides with something that has a collider and put that gameObject into a variable named "other" here
void OnTriggerEnter(Collider other)
{
// other.name is the name of the object in the scene
if (other.name == "Player")
{
// this will load a new scene
Application.LoadLevel("Scene Name");
}
}
Note if you are making a 2nd game its Void OnTriggerEnter2D(collider2D other)
if you wanna read the API https://docs.unity3d.com/ScriptReference/Application.LoadLevel.html https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html
Hope it helps :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612092755im_/https://answers.unity.com/themes/thub/images/avi.jpg)