MonoBehaviour 腳本無法從 ScriptableObject 腳本調用函數

安托萬

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 有多陌生,但這裡有一些基礎知識:

如果出現該錯誤,您可能沒有從對象視圖中引用可編寫腳本的對象:

  1. 您是否從資產菜單中創建了一個新的 WaveConfig 對象?
  2. MakeObjectMoveOnPath 腳本(在檢查器中)中的 Settings 字段是否包含對該 WaveConfig 對象的引用?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我無法用我的腳本繪製所有函數

有沒有辦法在 Google Apps 腳本中每隔幾秒調用一次函數?

無法從通過 pip 和 setuptools 安裝的 entry_points 腳本中的 exec() Python 腳本

腳本無法與 Qlik Sense 中的 STARTS WITH 函數一起使用

從 CLP 中的另一個腳本調用 sql 腳本

有沒有辦法在 Google Apps 腳本中每隔幾秒調用一次自定義函數?

松腳本 hline 函數

谷歌應用程序腳本:到達谷歌工作表的最後一行後調用另一個函數

無法使用簡單的 Python 腳本從包含 URL 的文件中檢索響應標頭

如何訪問當前調用和/或執行腳本的路徑和文件名 - 利用模塊內函數

無法在腳本 Powershell 中安裝包 NuGet

無法加載 Google Sheets 的腳本

Linux 腳本無法在 MacOS 上運行

將 Apps 腳本函數應用於 Google 表格中的其他行

如何在谷歌應用程序腳本中使用另一個函數停止一個函數?

如何使用參數在我的腳本中調用 void?

如何在 jupyter notebook 上調用帶有解析參數的 python 腳本

無法“交換”數據庫中的值的腳本

使用 Python 腳本的 ADF 管道中的 Azure 函數

使用 Pandas Resample 函數的多個腳本的 OHLC

用於存檔數據的 Google Sheets 腳本

使用 ES6 模塊從命令行(Node JS)運行腳本中的函數

將字符串列表/數組從我的 bash 腳本傳遞給 ansible 腳本

Shell/Bash - 腳本和函數衝突的位置參數

使用 pine 腳本中的函數循環數組推送

bash 腳本中函數參數周圍的文字雙引號

Jenkins 和 Shell 腳本 - 無法更改日期時間值

無法使用 Google Apps 腳本將新產品上傳到 shopify

無法使用“查找”在 shell 腳本中設置變量