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?
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