繁体   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