- Home /
New input system and Scene Manager
Hi! I'm new here in the unity community! So sorry for this... may be too beginner question. I'm trying to use one method from my "PlayerInputHandeler" script in order to change a scene in a OnTriggerEnter2D function. I've carrying data from one script to another in order to use animators and stuff, but always changing the "MonoBehaviour" for another class. But, here is the problem. I need to use "MonoBehaviour" for using the Scene Manager. So I tried to use the Input System in the scene switcher script, and then attach it to the Player, but It didn't work of course. This is the script of my Scene switcher.
//Variables
public string goToNextLevel;
private bool shouldLoad;
//Animations
public Animator transition; //Declaramos una nueva animación
public float transitionTime = 2f; //Declaramos el tiempo de carga
public bool EnterInput { get; set; }//Nuevo para entrar
private void ButtonCheck()
{
if (shouldLoad && EnterInput)
{
StartCoroutine(LoadLevel(goToNextLevel));
}
}
void OnTriggerStay2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
shouldLoad = true;
}
}
public void OnEnterInput(InputAction.CallbackContext context)
{
if (context.performed)
{
EnterInput = true;
Debug.Log("entrando");
}
}
IEnumerator LoadLevel(string goToNextLevel)
{
transition.SetTrigger("Start");//Play transition animation
yield return new WaitForSeconds(transitionTime);
SceneManager.LoadScene(goToNextLevel);//Load scene
}
}
The main goal on this is to press a bottom in my controller and if I Im in a OnTriggerStay2D change the scene. PS: May look extra large script, but there is a second onTriggerEnter2D option too, I deleted in order to post here.
Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220613022019im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trouble with changing the sensitivity of an axis 0 Answers
Scenes won't change when built 1 Answer
Missed Input Events with Joystick 0 Answers
Why does loading the scene not work? 2 Answers