从 FirstPersonController 访问另一个脚本

access another script from FirstPersonController

对不起我的英语!

我有一个名为 "MYJoystick.cs" 的脚本:

 public class MYJoystick : MonoBehaviour 
 {
     public static string myX;
 }

我想在 unity 5 中从 "FirstPersonController.cs" 访问 "myX"。我想在 FirstPersonController 的更新中这样写:

 private void Update()
 {
      MYJoystick.myX += 1;
 }

但它说 "The name `MYJoystick' does not exist in the current context"。

我该如何解决这个问题?我应该在 FirstPersonController 中添加 Using 吗?用什么?统一的默认命名空间是什么?我也尝试为我的脚本添加命名空间,但它也不起作用!

我刚遇到这个问题。

http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html

The basic rule is that anything that will be compiled in a phase after the current one cannot be referenced. The phases of compilation are as follows:

Phase 1: Runtime scripts in folders called Standard Assets, Pro Standard Assets and Plugins.

Phase 2: Editor scripts in folders called Editor that are anywhere inside top-level folders called Standard Assets, Pro Standard Assets and Plugins.

Phase 3: All other scripts that are not inside a folder called Editor.

Phase 4: All remaining scripts (ie, the ones that are inside a folder called Editor).

您的 FPSController c# 脚本位于标准资产文件夹中,这是 其他文件夹中的其他自定义 c# 脚本之前编译的。

要解决此问题,您可以将 'Standard Assets' 重命名为另一个名称,或者将此文件夹放入另一个文件夹,或者获取 FPSController 脚本并将其与其他脚本放在一起。 更好的解决方案是复制 FPSController 标准资产脚本并将其放入您的自定义文件夹,然后改为修改该脚本。

我尝试过更改脚本的编译顺序作为更好的解决方案,但似乎没有用。这只是 运行 时间与 Start()Awake() 我认为在脚本之间。