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

Question "Can't add script component because the script class cannot be found.

Discussion in 'Scripting' started by Striver4, Dec 6, 2021.

  1. Striver4

    Striver4

    Joined:
    Nov 2, 2021
    Posts:
    12


    Hi everyone
    Under this tutorial at 4:19:30 the tutor attaches the script no problem but when I do it it says "Can't add script component 'Camera Follow' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match."
    How is it fixed?
     
  2. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    Camera Follow, I suppose it should not contain a space? So rename your class AND file. You can use underscore instead but most people just would use CameraFollow.
    Spaces are not allowed in any names. And I'm not aware of a programming language supporting it (albeit I don't know many).
     
  3. Striver4

    Striver4

    Joined:
    Nov 2, 2021
    Posts:
    12
    Thank you for your reply. A little after posting this I found the answer to the problem in this video
    . What you said maybe would have helped me enough. Being a beginner, I didn't know what precisely was meant by 'file name' and 'class name' or where to find them. Being a beginner is horrible. When something goes wrong you've no idea what to do about it. But anyway, thanks!
     
  4. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    Beeing a "seasoned" dev is horrible too ;).
    Seriously. Just keep learning. For total beginners I like to suggest learning the principles of C# programming outside of Unity (since Unity doesnt make it easier as it adds alot of complexity). A good resource to start is the free C# Yellow book by Rob Miles. Basic principles like what a class is is explained there.
     
  5. Striver4

    Striver4

    Joined:
    Nov 2, 2021
    Posts:
    12
    Thank you very much for that. I'll check that out. Hopefully I'll have got the hang of it all someday.
    I've started following the Unity FPS Survival Game Tutorial YT video too.
    I'm finally pursuing a passion I've always had for games (I didn't take it seriously at first in life).
     
  6. Deleted User

    Deleted User

    Guest

  7. Striver4

    Striver4

    Joined:
    Nov 2, 2021
    Posts:
    12