簡體   English   中英

無法從其他腳本中找到 Class 的定義

[英]Can't find definition of Class from other script

我有兩個腳本:

1:我的播放器腳本

using Unity.FPS.Game;
using UnityEngine;
using UnityEngine.Events;
using Spells;

namespace Unity.FPS.Gameplay
{
    public class PlayerCharacterController : MonoBehaviour
    {

        FireBaseScript fireScript;
        ...
    }
}

2:我的火咒腳本:

using UnityEngine;
using System.Collections;

namespace Spells
{
    public class FireBaseScript : MonoBehaviour
    {
        ...
    }
}

兩個腳本都在不同的文件夾中,我在using Spells;

The type or namespace 'Spells' could not be found (are you missing a directive or assembly reference

我需要為我的播放器腳本做些什么來識別我的火咒腳本嗎?

編輯: - - - - - - - - - - - - -

所以我嘗試將FireBaseScript.cs復制到與 Player 腳本相同的文件夾中,它編譯得很好。 然后我做了一些谷歌搜索,發現統一文件夾是按波編譯的,而不是一起編譯的。 所以顯然/Scripts/Games/文件夾是在/Scripts/Spells/Animations/Fire文件夾之前編譯的。

我相信.asmdef文件可能與它有關,但不確定。 我嘗試將程序集定義文件添加到Spells文件夾並將其添加到Games.asmdef文件的Assembly Definition References中-但這仍然不起作用

有沒有辦法讓這兩個文件夾一起編譯?

在您的 FireSpell 腳本中,使用您的 class 名稱創建它的一個實例。 它應該看起來像這個 並將這段代碼放在你用來創建局部變量的地方。 然后在同一腳本中的 Awake() 或 Start() 方法中,確保只有一個可用的實例。 為此,請輸入以下代碼 . 在此之后,您可以在 Unity 內的任何其他腳本中使用此實例來訪問變量或函數。 要從其他腳本訪問變量,只需使用這段代碼 , use this piece of code whenever you need. ,在需要時使用這段代碼。

with the variable or method that you created as public variable or method in FireBaseScript.請確保將替換為您在 FireBaseScript 中作為公共變量或方法創建的變量或方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM