Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Script error

Discussion in 'Scripting' started by brucehjoyner, Mar 24, 2021.

  1. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12
    When I try to use a script to pick up a weapon it keeps saying "The referenced script on this Behaviour (Game Object 'Weapon_Launcher') is missing!" And "The referenced script (mEsh) on this Behaviour is missing!" Can anyone help me?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Yep. Your scripts are missing on the gameobject.

    I guess the first thing to check is make sure your script name and class names match.
     
    Joe-Censored likes this.
  3. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12
    The class name is the object name right? If thats true it now says "the associated script cannot be loaded. please fix any compile errors and assign a valid script"
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Class name is in the Script. So in your project, the script name might be WeaponLauncher. Then when you open the script it should say class WeaponLauncher
     
  5. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12
    So it should look like this upload_2021-3-24_16-53-57.png
     

    Attached Files:

  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Well, there is your problem. Your script is named mEsh and your class is named manager. They need to match.
     
    Joe-Censored likes this.
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This ^^^

    Either rename the class to "mEsh" or change the filename to "manager.cs" so they match. You might need to remove the missing component and add it again after this is fixed.
     
  8. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12
    Ok i did that i now have an error saying "Assets\mEsh.cs(8,12): error CS0246: The type or namespace name 'gameObject' could not be found (are you missing a using directive or an assembly reference?)" Heres the code Screenshot (166).png
     
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    In the future post code in the forum using CODE tags like below instead of posting images.
    Code (csharp):
    1. public GameObject WeaponLauncher;
    But the issue is your capitalization. On line 29 when you use "hit.transform.gameObject" the capitalization is correct, because "gameObject" is a reference to a specific instance of a GameObject. The correct capitalization for the type though is GameObject with a capital G.

    If you weren't aware, the error message includes the line number, in this case line 8, within the error message.
     
  10. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  11. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12