- Home /
(2D) Can't make a scene transition between 2 game objects colliding - 2019
Hello, I was hoping somebody might be able to help. I have a "Player" in the scene and I want it to hit an object (wormhole) and pass into the next level. I'm not getting any warning signs and both objects are on the same layer.
The the player hits the object (it has a collider) nothing happens. If somebody could offer any pointers that would be great.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveScene2d : MonoBehaviour {
void OnTriggerEnter(Collider ChangeScene) //
{
if(ChangeScene.gameObject.CompareTag("Player"))
{
Application.LoadLevelAdditive(1); //1 is the build order
Debug.Log ("loaded nxt level");
}
}
}
Also, I have tried hard writing the scene name "level2" and still nothing happens when they collide. Thanks, J
Answer by jimm84 · May 27, 2019 at 05:16 PM
Managed to potentially make this work. Need to tweak some of the original code and change 'collider' to "OnTriggerEnter2D" Works when built and tested.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MoveScene2d : MonoBehaviour {
void OnTriggerEnter2D (Collider2D collider)
{
// If the player hit the collider "with trigger ticked" it loads the next level
if(collider.tag == "Player")
SceneManager.LoadScene("level2");
Debug.Log ("loaded nxt level");
}
}
Your answer
Follow this Question
Related Questions
Next Level to unlock when first level is completed 2 Answers
How to switch between scenes? 0 Answers
When die - reset score from the last scene 2 Answers
How to make this scene changing? 1 Answer
Multiple Cars not working 1 Answer