MonoBehaviour 腳本:
public class MakeObjectMoveOnPath : MonoBehaviour
{
public WaveConfig settings;
// Start is called before the first frame update
void Start()
{
settings.OnUse();
}
// Update is called once per frame
void Update()
{
}
}
ScriptableObject 腳本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Enemy wave config")]
//a scirptable object is an object which is set from scirpt and used from unity
public class WaveConfig : ScriptableObject
{
public void OnUse()
{
Debug.Log("Test");
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
我想做的是測試我是否可以在調試控制台中從 MonoBehaviour 腳本調用 ScriptableObject 腳本中的方法。確保腳本在統一 2D 中工作但它給了我一個名為
NullReferenceException:未將對象引用設置為對象的實例
我不知道你對 Unity 有多陌生,但這裡有一些基礎知識:
如果出現該錯誤,您可能沒有從對象視圖中引用可編寫腳本的對象:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句