So, like you I don’t like hard-coded values. So I added a public variable for the scene name:
public class LoseCollider : MonoBehaviour
{
public string LoseScene = "Game Over";
private void OnTriggerEnter2D(Collider2D collision)
{
SceneManager.LoadScene(LoseScene);
}
}
This works fine and I can put the text name into the field and it’s no longer hard coded. I then thought, well how about if I just drag the scene into the field and use the name parameter from the Scene object. So I tried:
public class LoseCollider : MonoBehaviour
{
public Scene LoseSceneObj;
private void OnTriggerEnter2D(Collider2D collision)
{
SceneManager.LoadScene(LoseScene.name);
}
}
Well in the Inspector id doesn’t provide a way to drag in a scene object. Instead there is a Handle
parameter with and int (defaulted to 0). My thinking is that this is the build handle index, but not sure.
So my question is, would I be able to set this up in a way to be able to drag the Scene object to the field in the Inspector to get access to that object?
Thank you,
Brett