【Unity】コンストラクタ使えない問題

Warningが出た

下記のようなコードをかいた

HogeClass hoge = new HogeClass("A","B","C");

なんか怒られた。

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.

classをインスタンス化したから怒られったぽい。AddComponentしろと書いてある。AddComponentするとコンストラクタがつかえないのだが、どうしたらいいのか?

コンストラクタは使用しない仕様

unityのマニュアルより

Note for C# and Boo users: use Awake instead of the constructor for initialization, as the serialized state of the component is undefined at construction time. Awake is called once, just like the constructor.

初期化時にはAwakeイベントを使用する。初期化用のコンストラクタは定義しない。
ほほー。
MonoBehaviourはコンポーネントとして扱うことを前提に作られているようですね。
(ノ゚ο゚)ノ オオオオォォォォォォ-
めんどくさい。

こんなの作ってみた

Classにコンストラクタぽいものを用意した。

public class HogeClass : MonoBehaviour {
		
	private string nameA = "";
	private string nameB = "";
	private string nameC = "";

	public HogeClass newItemPanelContainer(string name1,string name2,string name3){
		nameA = name1;
		nameB = name2;
		nameC = name3;
		return this;
	}
}

こんな感じで使う

	private HogeClass hoge;

	void Awake(){
		hoge = gameObject.AddComponent<HogeClass> ();
		hoge.newHogeClass ("A","B","C");
	}

static使ったほうがいいかも。