Меню

Ошибка юнити cant add script component

If you still have the old copy of the project, upgrade the Unity project to Unity 2017 first then to 2018.2.2f1.

Here are the few possible reasons you may get this error(Ordered from very likely)

1.Script name does not match class name.

If script name is called MyClass, the class name must be MyClass. This is also case-sensitive. Double check to make sure that this is not the issue. To make sure that’s not the issue, copy the class name and paste it as the script name to make sure that this is not the issue.

Note that if you have have multiple classes in one script, the class name that should match with the script name is the class that derives from MonoBehaviour.


2.There is an error in your script. Since this is an upgrade, there is a chance you’re using an API that is now deprecated and removed. Open your script with Visual Studio and see if there is an error there then fix it. There is usually a red line under a code that indicates there is an error.


3.Bad import with the Unity importer and its automatic upgrade script.

Things to try:

A.The first thing to do is restart the Unity Editor.

B.Right click on the Project Tab then click «Reimport All»

C.If there is still issue, the only left is deleting the problematic script and creating a new one. There is an easier way to do this if the script is attached to many GameObjects in your scene.

A.Open the script, copy its content into notepad.

B.From the Editor and on the Project tab right click on the script «CubeScript», select «Find References In Scene».

C.Unity will now only show all the GameObjects that has this script attached to them. Delete the old script. Create a new one then copy the content from the notepad to this new script. Now, you can just drag the new script to all the filtered GameObject in the scene. Do this for every script effected. This is a manual work but should fix your issues when completed.

can’t add script component

Добрый день, при попытке добавить скрипт на GameObject выскакивает ошибка:
«Can’t add script component ‘Head’ because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.»
Я так понял, что юнити ругается на не соответствие названия скрипта и класса, хотя название скрипта и класса совпадают.В чем может быть причина?

редактор кода Visual studio 2019
юнити последняя версия

haawkeey
UNец
 
Сообщения: 1
Зарегистрирован: 06 май 2019, 12:34

Re: can’t add script component

Сообщение 1max1 06 май 2019, 13:11

Не наследуется от MonoBehaviour

Аватара пользователя
1max1
Адепт
 
Сообщения: 5281
Зарегистрирован: 28 июн 2017, 10:51

Re: can’t add script component

Сообщение AngryCat 08 май 2019, 21:27

Как написали выше, смотри, чтоб в название класса было написано «НАЗВАНИЕ_КЛАССА : MonoBehaviour». И еще. Не забывай, что название скрипта не может содержать пробелов!!

Здесь могла бы быть ваша реклама.

Аватара пользователя
AngryCat
Старожил
 
Сообщения: 713
Зарегистрирован: 20 июл 2018, 22:29
Skype: Дискорд — Флеш#4099


Вернуться в Почемучка

Кто сейчас на конференции

Сейчас этот форум просматривают: CatUnityDev и гости: 26



Once suspended, aishanipach will not be able to comment or publish posts until their suspension is removed.

Once unsuspended, aishanipach will be able to comment and publish posts again.

Once unpublished, all posts by aishanipach will become hidden and only accessible to themselves.

If aishanipach is not suspended, they can still re-publish their posts from their dashboard.

Note:

Once unpublished, this post will become invisible to the public and only accessible to Aishanii.

They can still re-publish the post if they are not suspended.

Thanks for keeping DEV Community 👩‍💻👨‍💻 safe. Here is what you can do to flag aishanipach:

Make all posts by aishanipach less visible

aishanipach consistently posts content that violates DEV Community 👩‍💻👨‍💻’s
code of conduct because it is harassing, offensive or spammy.

Unflagging aishanipach will restore default visibility to their posts.

$begingroup$

I’m a beginner in unity so I got this problem.
Here is the script:

using UnityEngine;
using System.Collections;
public class Playercontrol: MonoBehaviour {
    public float maxspeed = 10f;
    bool facingRight = true;

    void FixedUpdate () {
        float move = Input.GetAxis ("Horizontal");

        GetComponent<Rigidbody2D>().velocity
             = new Vector2(move * maxspeed, GetComponent<Rigidbody2D>().velocity.y);

        if (move > 0 && !facingRight){
            Flip ();
        } else if (move < 0 && facingRight) {
            Flip ();
        }
    }

    void Flip() {
        facingRight = !facingRight;
        Vector3 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;    
    }
}

I don’t know why but it keep saying that
Can’t add script component ‘Player control’ because the script class cannot be found.Make sure that there no compile errors and that the file name and class name match.

House's user avatar

House

72.9k16 gold badges180 silver badges270 bronze badges

asked Apr 25, 2015 at 15:30

Bob's user avatar

$endgroup$

4

$begingroup$

Check the file name of the script and make sure it’s the same as the class name. I’ve had this problem before after renaming a script through the editor.

answered Apr 25, 2015 at 18:33

Mason Dixon Ormous's user avatar

$endgroup$

2

$begingroup$

Old question, but I solved this problem using the Help menu and then Reset Packages to defaults.

answered Mar 4, 2021 at 18:45

Tarod's user avatar

TarodTarod

1116 bronze badges

$endgroup$

$begingroup$

You either have a compile error in this script, or you have one in a different script. If this is the first time you’re trying to use this script, the entire solution needs to compile before Unity knows about this new class you’re introducing.

Locate your error and correct it before trying to add this script. It could be a compile error or something like a name mismatch like SanSolo suggests.

answered Apr 25, 2015 at 16:43

House's user avatar

HouseHouse

72.9k16 gold badges180 silver badges270 bronze badges

$endgroup$

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Ошибка юнити all compiler errors have to be fixed before you can enter playmode
  • Ошибки df dla 15