- Home /
Help with loading a scene,Help changing scenes (C~ script)
When the player touches the box collider, it should transition to Level2
using UnityEngine;
using UnityEngine.SceneManagement;
public class Exit : MonoBehaviour
{
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "OVRPlayerController")
{
SceneManager.LoadScene("Level2");
}
}
}
nothing happens when I touch the cube with my player,Could someone help me with my script? When the player touches the collider, it should change to Level2
using UnityEngine;
using UnityEngine.SceneManagement;
public class Exit : MonoBehaviour
{
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "OVRPlayerController")
{
SceneManager.LoadScene("Level2");
}
}
}
Hmm still nothing happens when I touch the cube with my player
Answer by KjipGamer · May 16, 2018 at 10:44 AM
Make sure your "Level2" scene is also in the build settings, otherwise it will not work. If that's not the problem, you can check if it detects the collision by just adding a Debug.Log("Collision Occured")
inside of the void OnCollisionEnter(Collision col)
method.
A second problem could also be that either of your 2 objects don't have colliders on them.
Your answer
![](https://koobas.hobune.stream/wayback/20220612162758im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I access a variable from a different scene using C#? 3 Answers
How to generate an occupancy grid of the scene? 1 Answer
bool doesn't change?? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers