Can't add script problem

I don’t understand this. I really don’t. This question has been asked before, I know it has but I’m not finding the answer I’m looking for that would with my predicament. Whenever I try to add a script to an object, I get this, Can’t add component “so so” because it doesn’t exist. Check to see if the file name and class name match. Makes no sense to me. As far as I’m concerned with file names class names, it’s confusing the heck out of me. And I’m stating this now, it’s not a “one script problem” thing. It’s doing the same thing with all the other scripts I have except for the ones that have already been applied to objects, which means I’m not going to post every single code I have. And some of them haven’t been completed or started yet (the reason why is because I just want it already created so I don’t forget later), which makes even less sense, so it would be pointless for me to do that.

So, in a nutshell, I would appreciate it and be grateful if someone can shed some light on what to do here, please. Thank you.

Bold words or symbols = Important word or symbol

ok so the code class must match your file name on the 4th line (example: Name of script is Gear so on line 4 it should say public class Gear : MonoBehaviour )

also in coding at end of codes shold have a semicolon(:wink:
Example:

this is not a code just an example;

also the codes must be in a void and the void must be held by the 4th line using { and }

Example:

public class Gear : MonoBehaviour{

void NameWhatEver_NoSpaces{

above the symbol is counting what im saying now as part of code;

}   <-----those ended the two above basically simple organizing.

}

hope this helps :smiley:

You have a bunch of syntax errors. You will not be able to attach scripts that will not compile. You can look what I posted below. I also reformatted it since yours was hard to read.

public class icesword : MonoBehaviour 
{
    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.LeftShift)||Input.GetKeyDown(KeyCode.RightShift)); // <-- Don't place a semicolon here
        {
            float distance = 10.0f  // <-- Missing a semicolon
                // attach IceSword to Clark Eagleheart
                // make IceSword appear otherwise don't appear
       ;} //<-- Again with a random semicolon
    }
}

If you place a semicolon at the end of an if statement it just quits right there. Nothing will get called between the braces (true or not true)

regards,

When I had this error it was because the class name and script name didn’t match.
Try using copy/paste to ensure they are EXACTLY the same.

I get the same error before I’v even edited my scrit so it cant be an error in the code. Have you moved/delited anny of the unity files so that that miht cause an error? I also renamed my script after creating it witch created an error since the scrit name does not atomaticly cange in the code.

Remove the space in the name. it worked for me.

SOLUTION - PROVEN

I just had this same issue come up. And while sometimes it is not an issue, but especially if you have multiple scripts and then you have multiple compiler errors; then you will receive this message.

“Can’t add scripts because the file name cannot be found, check to be sure it matches its class name”

Simply, FIX the problems in all of your compiler errors, or //Comment out the problems you cannot fix. Once this is saved, you will then be allowed to add scripts again.

cheers!

I had this problem caused by naming the file WhateverClass.cs which Unity then tacked another .cs extension onto.

Try to first go to whatever it is you want too add a script to, highlight it go to Add Component scroll too New Skript give it a name than click Create and Add. try copy paste your script there, it worked for me

I had the same problem and I clicked on the gameobject for example “Player” and clicked on add componet and I added new script, named the script and opened the script from their. It worked perfect.

sorry for my english, I’m from Sweden

I found that forgetting to add a Cmd prefix to a [Command] function in another script made all scripts give me this error. Maybe that will help someone.

I was JUST having the same issue. My problem was the script was named Player Controller, but the file was named PlayerController.

The space in between was stopping me from adding the script to the player. Once I made the two match, it added the script.

If you still has this problem try drag-and-drop that particular object that has the script that you need on the place for script. @TheDragonBreather

I have a similar problem. the names are the same but the problem persists. Please help me.
[166340-ekran-alıntısı.png|166340]