Search Unity

The associated script can not be loaded

Discussion in 'Scripting' started by Nathanaji01, Jun 2, 2019.

  1. Nathanaji01

    Nathanaji01

    Joined:
    Oct 8, 2017
    Posts:
    24
    Hi. I am constantly getting this error. It pops up underneath the script component of the game object. It usually happens after I add a new public variable to the script. This problem is that it does this for all the scripts in the scene. I have tried removing it and adding it but nothing seems to work. Is there any way to fix this?
    upload_2019-6-2_15-17-16.png
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    4,870
    Please show error log from the console.
     
  3. Nathanaji01

    Nathanaji01

    Joined:
    Oct 8, 2017
    Posts:
    24
    This is the only error in the console:
    upload_2019-6-2_20-41-1.png
    I had followed a tutorial on how to make a loading bar in which a "public slider" was used. This is my code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.UI;
    6.  
    7. public class MainMenu : MonoBehaviour {
    8.  
    9.     public GameObject LoadingScreen;
    10.     public slider Slider;
    11.  
    12.     public void LoadLevel (int sceneIndex)
    13.     {
    14.         StartCoroutine(LoadAsynchronously(sceneIndex));
    15.     }
    16.  
    17.     IEnumerator LoadAsynchronously (int sceneIndex)
    18.     {
    19.         AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);
    20.         LoadingScreen.SetActive(true);
    21.  
    22.         while (!operation.isDone)
    23.         {
    24.             float progress = Mathf.Clamp01(operation.progress / 0.9f);
    25.             slider.value = progress;
    26.             yield return null;
    27.         }
    28.     }
    29. }
    The public game object works but for some reason, the public slider does not appear in the inspector window:
    upload_2019-6-2_20-46-6.png
    Soon after this, an error comes:
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    4,870
    Do you have mknkbehaviour scrip file called slider.cs, or similar? You have missing reference to that file.
     
    Nathanaji01 likes this.
  5. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    789
    Code (CSharp):
    1. public slider Slider;
    Should be:

    Code (CSharp):
    1. public Slider slider;
    There is no Slider class with a lowercase.
     
    Antypodish, Nathanaji01 and Vryken like this.
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    4,870
    Unless is custom class. But until OP try/confirm can not be sure of OP case.

    But yes I would try capitalize first letter.
     
    Nathanaji01 likes this.
  7. Nathanaji01

    Nathanaji01

    Joined:
    Oct 8, 2017
    Posts:
    24
    Thanks so much, I capitalized the S in Slider and it works. Thanks a lot.
     
    Antypodish and TaleOf4Gamers like this.
  8. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    789
    Agreed but judging by its usage, I am 99.9% certain that it refers to Slider in the UI namespace.

    EDIT:

    Glad it works!
     
    Nathanaji01 and Antypodish like this.