I am trying to make a molti level 2D game in unity, the problem shows up when u load the scene with a level, then u go to the main menu or complete the level and return to the map, and try to restart the same fisrt level. It also occours with the other levels, when i exit the scene of the first level all the codes inside it stop working and i cant move no more.
I use a button with this code for returning to the main menù from the level pause
public void OnBack() { SceneManager.LoadScene("Menu"); }
And i use this code for loading levels:
public void OnLvl1() { SceneManager.LoadScene("Lvl1"); }
The main problem is that the code of the player stops working and it stop moving and attacking, but i can continue to crouch.
private void OnMove(InputValue value )
{
movement = value.Get<Vector2>();
}
private void OnCrouch()
{
if( !crouch )
{
animator.SetFloat("crouch", 1);
}
else
{
animator.SetFloat("crouch", 0);
}
crouch = !crouch;
}
public void Update(){
if (!crouch && (movement.x != 0 || movement.y != 0) && !attacking && !performing)
{
transform.position = new Vector3(transform.position.x + movement.x * speed *
Time.deltaTime, transform.position.y + movement.y * speed * Time.deltaTime,
transform.position.z);
animator.SetFloat("speed", movement.x != 0? 1 :movement.y != 0? 1 :0);
}
else
{
animator.SetFloat("speed", 0);
}
}
for the input system i use the player input manager.