Switching Scenes In a parkour game

So I have a code already but I cant figure out why it says error

Assets\Scripts\Switch scenes.cs(17,37): error CS1003: Syntax error, ‘,’ expected.

because I don’t need a coma when I want to press down the 2 key.

what I want to happen Is when I press down the 2 key I want it to switch scenes, for example if I’m on scene one and I just completed the parkour level I want to go to level 2 right? well… it wont work. so I need someone’s help

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SwitchscenesL1 : MonoBehaviour
{
    public void Level2()
    {
        if (Input.GetKeyDown(KeyCode.2))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
        }
    }

    public void Level3()
    {
        if (Input.GetKeyDown(KeyCode.3))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
        }
    }

    public void Level4()
    {
        if (Input.GetKeyDown(KeyCode.4))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 3);
        }
    }
}

Try this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SwitchscenesL1 : MonoBehaviour
{
    public void Level2()
    {
        if (Input.GetKeyDown(KeyCode.2))
        {
            SceneManager.LoadScene(Scene No. for lvl 2);
        }
    }

    public void Level3()
    {
        if (Input.GetKeyDown(KeyCode.3))
        {
            SceneManager.LoadScene(Scene No. for Lvl 3);
        }
    }

    public void Level4()
    {
        if (Input.GetKeyDown(KeyCode.4))
        {
            SceneManager.LoadScene(// Scene no. for Lvl 4);
        }
    }
}
```[quote="Robbie_VR, post:1, topic:339868, full:true"]
So I have a code already but I cant figure out why it says error

> Assets\Scripts\Switch scenes.cs(17,37): error CS1003: Syntax error, ',' expected.

because I don't need a coma when I want to press down the 2 key.

what I want to happen Is when I press down the 2 key I want it to switch scenes, for example if I'm on scene one and I just completed the parkour level I want to go to level 2 right? well... it wont work. so I need someone's help

```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SwitchscenesL1 : MonoBehaviour
{
    public void Level2()
    {
        if (Input.GetKeyDown(KeyCode.2))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
        }
    }

    public void Level3()
    {
        if (Input.GetKeyDown(KeyCode.3))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
        }
    }

    public void Level4()
    {
        if (Input.GetKeyDown(KeyCode.4))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 3);
        }
    }
}

[/quote]

The “Scene No.” is the number of the scene. If you go to File → Build Settings (if you need to press Add Open Scenes) youll see each scene and to the right youll see numbers. Those are scene numbers.

I don’t think “2” is a valid KeyCode. KeyCode.Alpha2 is used for the 2 key at the top of the keyboard and KeyCode.Keypad2 is used for the 2 key on the numpad.

Had an issue like this before. Make sure to add:

using Unity.SceneManagement

and then you can use

SceneManager.LoadScene("Level2");

to load another level.

Please note:

I used scene name not scene number.