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