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. Dismiss Notice

Question I have a problem with a script!!

Discussion in 'Scripting' started by GameDev_A, Jun 28, 2023.

  1. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    37
    Hi everyone, I was programming, and while I was trying to insert a script into a game object, the warning that is present in the screenshot I attached appears to me, how can I do it? because i checked and the names are the same also there are no errors in the script. Thank you
     

    Attached Files:

  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    It tells you either the script and the class name don't match (Caps matter!)
    Or, you have compile errors. So, look for errors in console.
     
    Bunny83 likes this.
  3. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    37
    There aren't error and the names are the same
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Show a screenshot of your Unity console, the script in your project folder, and the script class name.

    Note, clear the console so only compiler errors appear.
     
  5. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    37
    Ok tomorrow I'll take the screenshot
     
  6. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    37
    This is what I wrote as the file and class name
     

    Attached Files:

  7. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Ok, and in console, if you clear it, there are no errors remaining? I'm not talking just this script, which is why we're looking in console.
     
  8. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    37
    I have only two errors of com.unity.ext.nunit@1.0.6, which just appeared to me because I updated a package and two errors of another code, nothing else, however I tried to add other scripts to other game object but it gives me the same error
     
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Well, that is likely your problem. Compile time errors, usually with your code, prevent you from adding scripts to gameobjects. It doesn't matter what script those errors occur in. If they are your own scripts, you need to fix them.

    When it comes from a package, that's a bit more iffy. It can prevent you from adding scripts to objects, but not always when they are editor errors. These errors don't have to be in the scripts you are adding to objects.

    When it tries to recompile, if it can't finish, then you run into problems.
     
  10. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    37
    OK, now I try to compile the code
     
  11. GameDev_A

    GameDev_A

    Joined:
    Sep 5, 2022
    Posts:
    37
    Sono riuscito a togliere tutti gli errori, anche quelli del pacchetto ed ora funziona perfettamente, grazie!!