@aeaeae1

Выводит ошибку в Unity в чем проблема?

В чем проблема Unity выводит следующюю оошибку
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor()
CoreClient:.ctor() (at Assets/Code/CoreClient.cs:36)
AnimatorController:.ctor() (at Assets/Code/AnimatorController.cs:9)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimatorController : MonoBehaviour
{
  
    private Animator anim;
    private CoreClient core = new CoreClient();

    void Start()
    {
        //try
        //{
        //    StartServer();
        //}
        //catch (Exception e)
        //{
        //    Debug.Log("<color=red>ERROR: </color> " + e);
        //}
       
        anim = gameObject.GetComponent<Animator>();
        core = gameObject.GetComponent<CoreClient>();
    }
  • Вопрос задан
  • 483 просмотра
Пригласить эксперта
Ответы на вопрос 2
GavriKos
@GavriKos Куратор тега Unity
Ну так почитайте что в ошибке написано. Прямым текстом же - не создавайте MonoBehaviour через New
Ответ написан
MANAB
@MANAB
Разрабатываю на C#: Web, Desktop, Gamedev
CoreClient core = new CoreClient(); заменить на CoreClient core = null;
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы