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

Начал изучать unity по гайдам, делаю шахматы. Возникла такая проблема: скрипт работает в самой юнити а в билде нет. Может в коде есть ошибки? В гугле решение не нашел, хотя насколько понял проблема часто встречается.

public class Rules : MonoBehaviour
{
    DragAndDrop dad;
    public Rules()
    {
        dad = new DragAndDrop();
    }

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        dad.Action();
    }
}

class DragAndDrop
{
    enum State
    {
        none,
        drag
    }

    State state;
    GameObject item;

    public DragAndDrop()
    {
        state = State.none;
        item = null;
    }
    public bool Action()
    {
        switch (state)
        {
            case State.none:
                if (IsMouseButtonPressed())
                    PickUp();
                break;
            case State.drag:
                if (IsMouseButtonPressed())
                    Drag();
                else
                    Drop();
                return true;
        }
        return false;
    }
    bool IsMouseButtonPressed()
    {
        return Input.GetMouseButton(0);
    }
    void PickUp()
    {
        Vector2 clickPosition = GetClickPosition();
        Transform clickedItem = GetItemAt(clickPosition);
        if (clickedItem == null) return;
        item = clickedItem.gameObject;
        state = State.drag;
        Debug.Log("picked up: " + item.name);
    }
    Vector2 GetClickPosition()
    {
        return Camera.main.ScreenToWorldPoint(Input.mousePosition);
    }
    Transform GetItemAt(Vector2 position)
    {
        RaycastHit2D[] figures = Physics2D.RaycastAll(position, position, 0.5f);
        if (figures.Length == 0)
            return null;
        return figures[0].transform;
    }
    void Drag()
    {
        item.transform.position = GetClickPosition();
    }

    void Drop()
    {
        state = State.none;
        item = null;
    }
}

Ответы (1 шт):

Автор решения: Boronnikov Andrey

Ты пытаешься создать экземпляр класса, наследуемого от MonoBehaviour:

public Rules()
{
    dad = new DragAndDrop();
}

Так делать нельзя. Редактор позволяет пропускать ошибки, но это не всегда работает в билдах. Попробуй делать инициализацию DragAndDrop в методе Start или Awake. Что-то вроде:

void Start()
{
    dad = new DragAndDrop();
}
→ Ссылка