I can't edit public string in the inspector.

I’m having trouble switching scenes using a 2d box collider in unity.
This is the script on the box collider.

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

public class loadNewArea : MonoBehaviour
{
    public string levelToLoad;
  
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.name == "Player")
        {
            SceneManager.LoadScene(levelToLoad);
         
        } ;
    }
}

It shows in inspector it’s grey’d out and will not let me change it’s value to tell it what level to load.
There are no issues to stop from building and running the game.

In the screenshot “Level To Load” doesn’t look grayed out to me. (The above line naming the Script is grayed.) If you change your line 8 to say public string levelToLoad = "Assets/NameOfScene"; does the text Assets/NameOfScene appear, and does it appear gray?

Greyed out may not be the right way to put it but im not exactly sure whats wrong. This is the result after changing the code.

still nothing appears in the text area and i cant edit it. This is the new code

ublic class loadNewArea : MonoBehaviour
{
    public string levelToLoad = "Assets/Art/Map/testarea1";
   
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.name == "Player")
        {
            SceneManager.LoadScene(levelToLoad);
          
        } ;
    }
}

Extra semi colon line 23

1 Like