0

I have this script that allows me to change to a different scene when I push a button. I've used it multiple times before with no issue, but recently I've been getting this compiler error that's telling me the script can't be accessed due to its protect level. I did some research and it supposedly means something is set to private instead of public, but everything in my script is public to begin with. Please help? According to Unity, the error is the ".LoadScene" inside public void DoSceneChange().

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

public class SceneChange : MonoBehaviour
{
    [SerializeField]
    string levelToLoad;

    public void DoSceneChange()
    {
       SceneManager.LoadScene(levelToLoad);
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • put the exact error message in your question, people will be able to help you better – JohnD Aug 22 '18 at 13:10
  • @JohnD the message it gives me is "CS0122 - 'SceneManager.LoadScene(string)' is inaccessible due to its protection level" – MadDog Gaming Aug 22 '18 at 13:16
  • What is unclear about the error message? You are trying to call a static method named LoadScene on type SceneManager that is private (note that omitting an access level specifier will also default the member to private). – Igor Aug 22 '18 at 13:22
  • I would recommend going to the definition of SceneManager's LoadScene method. Make sure you are calling the right one, and have the right version of the unity libraries. – JohnD Aug 22 '18 at 13:32
  • @JohnD your idea helped me a lot! I changed the name of the class and tweaked the line inside public void DoSceneChange(). Thank you so much! – MadDog Gaming Aug 22 '18 at 14:58

0 Answers0