Search Unity

I can't edit public string in the inspector.

Discussion in 'Editor & General Support' started by danknakedart, Jun 30, 2019.

  1. danknakedart

    danknakedart

    Joined:
    Jun 29, 2019
    Posts:
    2
    I'm having trouble switching scenes using a 2d box collider in unity.
    This is the script on the box collider.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class loadNewArea : MonoBehaviour
    7. {
    8.     public string levelToLoad;
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.        
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.        
    20.     }
    21.  
    22.     void OnTriggerEnter2D(Collider2D collision)
    23.     {
    24.         if (collision.gameObject.name == "Player")
    25.         {
    26.             SceneManager.LoadScene(levelToLoad);
    27.          
    28.         } ;
    29.     }
    30. }
    31.  
    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.

     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,445
    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?
     
  3. danknakedart

    danknakedart

    Joined:
    Jun 29, 2019
    Posts:
    2
    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

    Code (CSharp):
    1. ublic class loadNewArea : MonoBehaviour
    2. {
    3.     public string levelToLoad = "Assets/Art/Map/testarea1";
    4.    
    5.     // Start is called before the first frame update
    6.     void Start()
    7.     {
    8.        
    9.     }
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.        
    15.     }
    16.  
    17.     void OnTriggerEnter2D(Collider2D collision)
    18.     {
    19.         if (collision.gameObject.name == "Player")
    20.         {
    21.             SceneManager.LoadScene(levelToLoad);
    22.          
    23.         } ;
    24.     }
    25. }
    26.  
     
  4. AndyZuntz

    AndyZuntz

    Joined:
    Mar 12, 2021
    Posts:
    5
    Extra semi colon line 23
     
    SalmonUnity likes this.