【问题标题】:C# cant find a unity auto generated classC# 找不到统一自动生成的类
【发布时间】:2019-12-31 23:23:06
【问题描述】:

好的,我正在学习使用新的 InputActions,并使用

创建了一个 C# 脚本

https://prnt.sc/oyaj5l

这就是我得到的:

// GENERATED AUTOMATICALLY FROM 'Assets/PlayerControls.inputactions'

using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;

public class PlayerControls : IInputActionCollection
{
    private InputActionAsset asset;
    public PlayerControls()
    {
        ///
    }
}

但是当我尝试创建一个 PlayerControls 对象时,我收到一个错误提示

找不到类型或命名空间名称“PlayerControls”(您是否缺少 using 指令或程序集引用?)

这是我尝试引用它的类:

using System;
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
using UnityEngine.InputSystem;

namespace UnityStandardAssets.Characters.FirstPerson
{
    public class FirstPersonController : MonoBehaviour
    {
        private PlayerControls controls; // ERROR HERE
    }
}

【问题讨论】:

  • 刚刚检查,我无法从 FirstPersonController 类引用我在全局命名空间中创建的任何脚本

标签: c# visual-studio class unity3d namespaces


【解决方案1】:

PlayerControls 类包装在命名空间中,然后在您的类中添加一个using 语句,该语句指向您的PlayerControls 类所在的命名空间。

【讨论】:

  • 是的,但 PlayerControls 类在全局命名空间中?见第一个代码
  • 看起来没有围绕 PlayerControls 类声明任何命名空间。
  • 还是不行..我可以访问统一的默认类,但不是我自己的
  • 能否更新您的问题以显示新代码?
  • @TrevorBrooks 如果你没有在自定义命名空间中显式包装一个类,它会被添加到"default" or "global" namespace,它会自动出现在每个文件中......所以这不应该是问题。
【解决方案2】:

我解决了! 看起来 Unity 有一个编译顺序。我引用了这个:http://answers.unity.com/answers/1274460/view.html 并在看到“标准资产”优先于其他资产后设法解决它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-18
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    相关资源
    最近更新 更多