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

Can't add scripts to anything

Discussion in 'Editor & General Support' started by davidsports, Nov 18, 2014.

  1. davidsports

    davidsports

    Joined:
    Aug 30, 2014
    Posts:
    8
    Hello,

    I'm kind of new to Unity and whenever I have a script I get the error "Can't add component "Example Component name" because it doesn't exist. Check to see if the file name and class name match".

    I also get a red error on the bottom about an unexpected token.

    I made a basic script for a car and tried to add it to Unity's SUV asset but I get those errors.

    Even more confusing, all I did is add a camera, and drag Unity's asset java script "SmoothFollow" and still get the first error.

    This never happened until I tried adding the car script.

    Please help.

    Thank you very much,

    David
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Does the name of the script, march the name of the class? Look at the script...
     
  3. davidsports

    davidsports

    Joined:
    Aug 30, 2014
    Posts:
    8
    Thank you for your response. What is the class name? Is it something in the script I set?

    Thank you very much,

    David
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    The class name is the public class accessed by unity.

    So, you create your script in Unity and name it. That name becomes the class name. Make sure, if you are suing c# that they are the same.
     
  5. davidsports

    davidsports

    Joined:
    Aug 30, 2014
    Posts:
    8

    By creating in Unity do you mean in MonoDevelop? And I'm using JavaScript, but in unity I'm pretty sure it's the same.

    Thank you,

    David
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The reason why you can't add any script to a game object is because there is a compilation error in at least one of your script. That means your code is not valid and as such you can't add anything. You have to resolve all compilation errors first.
     
    renman3000 likes this.