![](/img/trans.png)
[英]Visual studio can't find definition for TakeDamage from another method
[英]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.