Change scene

Hi there,

I made a 2d cube and i attached a script that if you click the cube, the Player game object walks towards the cube. That works.

Now I want to change the scene as soon as the player hits the cube. If found this script which should work.

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class SwitchLevel : MonoBehaviour {

    public string levelToLoad;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void OnTriggerEnter(Collider other)
    {
        if(other.tag == "Player")
        {
            SceneManager.LoadScene(levelToLoad);
        }
    }
}

But when the Player hits the cube, no new scene is loaded.

I have attached the Player-tag to the player game object (which walks towards the cube), i placed the name of the scene in the empty box in the inspector and attached a box collider to the cube and the player en made the cube a trigger.

I hope someone can help me out with this problem. Thank you in advance!

Cheers,

Jonah

void OnCollisionEnter(Collision myCollision)
{
if(myCollision.gameObject.tag == “Player”)
{
Application.LoadLevel(“Scene Name”);
}
}

I found this laying around and is not mine:
Answer by Vice_Versa · Sep 14, 2015 at 01:13 AMhttp://answers.unity3d.com/questions/1066454/on-collision-enter-next-scene.html link text

I myself am a Very newbie but this example is naming the Collision to the game Object being the active player. Your example is vague left opened, if you get my point, insert it and SEE?? It is my guest and only offered as I am learning as I go. Hope it helps you out …Peace… PS reply back if it does,thanks

I found the solution using a javascript code that i found here: