Почему unity не видит скрипт
Перейти к содержимому

Почему unity не видит скрипт

How to solve “Can’t Add Script” in Unity

In this article we look at the causes of the “Can’t Add Script” error in Unity in order to understand why it occurs and identify what actions to take to fix it.

Why do the “Can’t Add Script” Error occur in Unity?

This error in which we are not allowed to add a Script or component to a GameObject can arise for two reasons.

Case 1: The name of the script and the name of the class it defines do not match

The first one is that the name of the Script, that is to say, the name of the file with extension “.cs” does not match the name of the programming class that is defined inside it. This usually happens when we create a Script and then change the name of the file without doing a Refactoring process.

To solve this problem first we must identify the Script that has conflicts, this can be done with the information provided by the “Can’t Add Script” error window that appears when we try to add the Script with conflicts to a GameObject. If you do not remember which Script produced the error, you can create an Empty GameObject and start adding each of the Scripts until the error appears.

Once we know which is the Script that generates the “Can’t Add Script” error, we open it and we locate the part of the class definition, which begins as follows:

public class NameOfTheClass …

The name of the class is the name that has to match the name of the file, so what you can do is modify the name of the class to match the name of the file, or modify the name of the file to match the name of the class.

Once this problem is solved it will be possible to add the Script to a GameObject. If you need to rename the Script the best way is to right click on the “NameOfTheClass” name and then click on “Rename”, this will make Unity modify that name in all the places where that Script is used.

Case 2: The script was created having errors in the console

The second reason why the “Can’t Add Script” error occurs in Unity is when new Scripts are created while there are errors in console, in general these are syntax errors (errors in writing the code). The reason in this case is that if there are errors in console, Unity can not compile, therefore if we create a new Script at this point, even if the file has been created, the programming class can not be added to the engine, in other words Unity will not know that this Script exists until it compiles.

The solution in this case is to solve all the errors in the console, this will make Unity compile and register the new Script. From that point on you will be able to assign the Script to a GameObject.

Не работают скрипты в Unity3D.

Пробовал убирать лишние библиотеки, менять значения. Короче говоря все пробовал, но чет все равно не запускается.

Фотографии ниже.
/> />

1)Во-первых надо было поменять тип сохраненя скрипта (тут до меня дошло что сохраняется не так как надо)
2)Во-вторых, надо мыло к спрайту привязать скрипт через «Add component»;
3) Поменять код: using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Oblachko : MonoBehaviour <

// Use this for initialization
void Start () <
transform.position = new Vector3(-12, 0.51f, -1f);
>

// Update is called once per frame
void Update ()
<

transform.Translate(new Vector2(0.1f, 0)*Time.deltaTime);
if (transform.position.x > 5)
<
Destroy(gameObject);
>
>
>

вот те универсальная инструкция, я нашел сотни уроков:

1. в ютубе забей: как создать 2d игру и дописывай по одному: game maker, blender 3d, unity 5. начни с 2d — меньше возни с графикой, кодом. начни с дна. это «скелет и мясо» твоей игры.
2. выбери ЯП — это «мозги» для твоей игры.
3. сначала сделай версию для ПК, ибо тут меньше проблем и народу тьма.
4. не строй имперские планы, начни с малого.
5. сначала сделай что-то бесплатное, выложить можешь тут: small-games info, vsetop com. там твою игру быстро проверят и оценят. атм есть раздел создание игр. смотри. зарегайся, спрашивай на форуме там же.
——-
по five night at freddy’s на gamejolt com при поиске выдает больше 100 клонов. в ютубе смотри прохождения, five night at (wario’s, crusty crubs, tomas) будет хоть основа.

Почему кнопка не видит функции моего скрипта Unity?

не видит функциюЗдравствуйте. Я создал кнопку и повесил на неё скрипт. Кнопка не видит функцию из моего скрипта. Модификатор доступа у функции стоит public. Что мне делать?введите сюда описание изображения

Знаете кого-то, кто может ответить? Поделитесь ссылкой на этот вопрос по почте, через Твиттер или Facebook.

Посмотрите другие вопросы с метками c# unity3d unity3d-ui или задайте свой вопрос.

Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2022.6.10.42345

Нажимая «Принять все файлы cookie», вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *