Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
16
Question by Psyminator · May 08, 2015 at 07:58 PM · scriptingbasics

Can't add script bacause of class cannot be found

What does it mean Can't add script component ... because the script class cannot be found?

I'm trying to make two hydraulic cylinders to point at each other with a LookAt-script in a mechanical rigg. But I seem not to be able to put the script on the object to even begin with...

What sort of function does this script class serve? Trying to learn =)

The script I'm using comes from the LookAt-tutorial. And it looks like this:

using UnityEngine; using System.Collections;

public class CameraLookAt : MonoBehaviour { public Transform target;

 void Update ()
 {
     transform.LookAt(target);
 }

}

I would really appreciate an answer even though I recognize I'm a total beginner with scripts.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hbalint1 · May 08, 2015 at 08:00 PM 2
Share

you sure that the file's name matches the class name?

avatar image squidBob · Sep 14, 2016 at 12:52 AM 0
Share

Same problem, I renamed it and I got a problem! the name is UpdatePos.

Here is my script, its from the scripting wiki btw:

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : $$anonymous$$onoBehaviour
 {
     void Start()
     {
         transform.position = new Vector3(0, 0, 0);
         print(transform.position.x);
     }
 }
avatar image nightbane30 squidBob · Sep 14, 2016 at 01:06 AM 0
Share

Change it to this:

  using UnityEngine;
  using System.Collections;
  
  public class UpdatePos : $$anonymous$$onoBehaviour
  {
      void Start()
      {
          transform.position = new Vector3(0, 0, 0);
          print(transform.position.x);
      }
  }

All I did was change the class name from ExampleClass to UpdatePos.

5 Replies

· Add your reply
  • Sort: 
avatar image
43
Best Answer

Answer by nightbane30 · May 08, 2015 at 11:10 PM

Make sure that the name of your script is also CameraLookAt. The class name and file name have to be the same in order for it to work.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Psyminator · May 11, 2015 at 10:15 AM 0
Share

It worked! Thank you very much =D The problem now seem to be the object the script is applied to points more like -90° wrong ins$$anonymous$$d of directly towards the target. I tried to offset the rotation +90° in the opposite direction. Hoping it'll help, but it did no good. Yet it seem to move correctly in correspondence with the animation.

Any idea, how I can make it to actually point at the target?

avatar image flipblip · Feb 26, 2016 at 09:11 AM 0
Share

Thanks That Really Help :)

avatar image yxxxx · Sep 22, 2016 at 09:48 PM 0
Share

I wasn't sure how to correct the file name in unity itself but found that you can rename the file in the file directory "explorer" and it works.

avatar image GabrielBB · May 14, 2017 at 03:06 PM 0
Share

Now it works :)

avatar image Fab49ers · Oct 04, 2017 at 01:10 PM 0
Share

That worked for me! Thank you so much!

Show more comments
avatar image
2

Answer by german_g · Jan 17, 2018 at 08:33 PM

Just wanted to add an explanation to that great answer above: Usually that problem arises when you create a script file and then rename it. Each time you create a script file, Unity creates a public class with the name you initially give to that script file. So when you rename the script file, it becomes disconnected from that public class. To do a quick check, select the script file in Unity's project window and look at the inspector window to compare script file and class names. In the example below script file name must be PlayerMove

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerMove : MonoBehaviour {
 }



Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dunnopineapple · May 10, 2018 at 09:21 PM 0
Share

Quick question, so dose this mean that their can't be spaces in the script files name?

avatar image Max_Bol Dunnopineapple · Sep 05, 2018 at 04:50 PM 0
Share

Yes, that means that scripts cannot have space unless you thinker some sorts of converter in Unity that automatically remove the space whenever it request a class that includes spaces.

To be honest, that's more of a waste of memory for the editor (since it got to check it out every single time it check for the class). All you got to do is think = Space. So, as an example, Env Light $$anonymous$$anager.cs would be *Env_Light$$anonymous$$anager.cs* ins$$anonymous$$d if you really need some kind of spaces in the nomenclature of your project's workflow.

avatar image
1

Answer by ryanm007 · Sep 20, 2021 at 01:34 AM

For me, the problem was that there was an error in another script.

Once I fixed the error, I could FINALLY attach my other scripts onto my gameobjects.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Psyminator · Sep 14, 2016 at 07:26 AM

Thanks a lot =D

I'm really grateful for you answers guys!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ahmedaniss · Aug 29, 2020 at 07:47 AM

problem fixed here : https://youtu.be/dx35_RNnJEQ

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

When to use a namespace? 2 Answers

float and int on player prefs 1 Answer

Learner Scripter... trying to make a basic move function. 1 Answer

How to set a special prefab in a switch? 1 Answer

Im trying to teleport my player between two spots - How do I do this? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges