- Home /
Question by
nartin9 · May 10, 2018 at 05:01 PM ·
unity 2dscene-switching
,lvl Change not working
,using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class level1Load : MonoBehaviour {
void OnCollisionEnter(Collision other)
{
//other.name should equal the root of your Player object
if (other.gameObject.tag == "Player")
{
//The scene number to load (in File->Build Settings)
SceneManager.LoadScene("Level1");
}
}
} Script for chest void OnCollisionEnter(Collision otherObj) { if (otherObj.gameObject.tag == "Enemy") { SceneManager.LoadScene(SceneManager.GetActiveScene().name); }
if (otherObj.gameObject.tag == "chest1")
{
//The scene number to load (in File->Build Settings)
SceneManager.LoadScene(1);
}
}
} Playerscript
I can restart the scene but I can't switch to a new lvl. there is a collision between player and chest but nothing happens.
Comment
Answer by Kek_Kek · May 10, 2018 at 05:13 PM
Try makeing the scene a int variable.
For Example
public int scene;
// The scene number would be the int. Say Level 1 = 1 in build settings.
public void OnTriggerEnter(Collider otherObj){
if(otherObj.gameObject.tag == "chest1"){
SceneManager.LoadScene(scene);
}
}
Try using that
Your answer
