'scrip class can't be found for adding c# code to unity for loading scenes
I am attempting to add a c# script to python allowing me to use UnityEngine.SceneManagement to load a scene of a game for a school assignment I am completing, but whenever I try to add the code to unity I get an error message stating "Can't add script component 'menu control' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match". I am relatively new to C# and wouldn't be surprised if there was just some small error in my code I couldn't spot. Here is my code below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MenuController : MonoBehaviour
{
[Header("Levels to load")]
public string _newGameLevel;
private string levelToLoad;
[SerializeField] private GameObject noSavedGameDialogue = null;
public void newgameYes()
{
SceneManager.LoadScene(_newGameLevel);
}
public void loadgameYes()
{
if (PlayerPrefs.HasKey("Savedlevel"))
{
levelToLoad = PlayerPrefs.GetString("SavedLevel");
SceneManager.LoadScene(levelToLoad);
}
else
{
noSavedGameDialogue.SetActive(true);
}
}
public void QuitButton()
{
Application.Quit();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
