play level script error

Hi im trying to make a script for the start of my level so when I hit play this script starts at the right level

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class PlayButtonLevelScript : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + PlayerPrefs.GetInt(“levelAt”);
}
void start()
{
PlayerPrefs.SetInt(“levelAt”, 1);
}
}

however I keep getting an error when I try and use the script. Any suggestions on how I can fix it?

  1. use code formatting (see first post in forums)
  2. what is the error (full text and line number)
  3. add any other things you might think are interesting; we’re not at your desk or in your mind.
1 Like

Everything @Kurt-Dekker said.

But I’ll toss out the only thing I see at a glance. start should be Start

1 Like
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class PlayButtonLevelScript : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + PlayerPrefs.GetInt("levelAt");
}
void Start()
{
PlayerPrefs.SetInt("levelAt", 1);
}
}

That code shouldn’t even compile, you are missingh a “)” in line 11

You should only post code that you know at least compiles.

1 Like