Answer the question
In order to leave comments, you need to log in
Shows an error in Unity what's the problem?
What's the problem Unity throws the following error
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>();
}
Answer the question
In order to leave comments, you need to log in
Well, read what is written in the error. In plain text - do not create MonoBehaviour via New
CoreClient core = new CoreClient(); replace with CoreClient core = null;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question