言語:C#
詰まったのでメモ。
エラーが出た例
NewBehaviourScript.cs
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GameObject obj;
void Start (){
obj.AddComponent("Sample.cs");
}
}
objにSample.csを追加しようと
obj.AddComponent("Sample.cs");
「新しいバージョン用のスクリプトに書き換えます」的なことを言われるので
[I Made a Backup. Go Ahead!]をクリックして進む
void Start (){
UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(obj, "Assets/NewBehaviourScript.cs (9,3)", "Sample.cs");
}
に書き換えられた
実行してみる
Component Type 'Sample.cs' not found.
とエラーが出てしまった。
エラー回避
gameObject.AddComponent<コンポーネント名>();
とするとうまくいく
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GameObject obj;
void Start (){
obj.AddComponent<Sample>();
}
}