【问题标题】:Unity player controller giving CS0246 errorUnity 播放器控制器给出 CS0246 错误
【发布时间】:2022-07-17 05:08:30
【问题描述】:

我在第 19 行第 16 字符出现错误,出现 CS0246 错误,此代码取自公共字符控制器,因此我不确定发生了什么。该错误还显示在 IPlayerController 的第 14 行字符 52 上。

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using TarodevController;

namespace TarodevController
{
    /// <summary>
    /// Hey!
    /// Tarodev here. I built this controller as there was a severe lack of quality & free 2D controllers out there.
    /// Right now it only contains movement and jumping, but it should be pretty easy to expand... I may even do it myself

    /// </summary>
    public class PlayerController : MonoBehaviour, IPlayerController
    {
        // Public for external hooks
        public Vector3 Velocity { get; private set; }
        public FrameInput Input { get; private set; }
        public bool JumpingThisFrame { get; private set; }
        public bool LandingThisFrame { get; private set; } = false;
        public Vector3 RawMovement { get; private set; }
        public bool Grounded => Cooldown;

        private Vector3 _lastPosition;
        private float _currentHorizontalSpeed, _currentVerticalSpeed;
    }
}

谢谢你,如果你知道发生了什么,代码在输入部分再次引用,用于计时。

 private void GatherInput()
        {
            Input = new FrameInput
            {
                JumpDown = UnityEngine.Input.GetButtonDown("Jump"),
                JumpUp = UnityEngine.Input.GetButtonUp("Jump"),
                X = UnityEngine.Input.GetAxisRaw("Horizontal")
            };
            if (Input.JumpDown)
            {
                _lastJumpPressed = Time.time;
            }
        }

如果有帮助,这里是完整的代码,https://github.com/Matthew-J-Spencer/Ultimate-2D-Controller/blob/main/Scripts/PlayerController.cs

编辑,这是错误消息:

PlayerController.cs(19,16):错误 CS0246:找不到类型或命名空间名称“FrameInput”(您是否缺少 using 指令或程序集引用?)

【问题讨论】:

  • 发帖时请使用错误名称,不要使用错误代码,因为大多数人没有记住这些代码。
  • 请粘贴完整的错误消息和堆栈跟踪,或发布在 Unity 控制台中选择的错误的屏幕截图,以便我们查看错误的详细信息。
  • PlayerController.cs(19,16):错误 CS0246:找不到类型或命名空间名称“FrameInput”(您是否缺少 using 指令或程序集引用?)抱歉,这是错误信息
  • 您缺少定义 FrameInput 的脚本。这就是为什么您会收到'FrameInput' could not be found 的声明。我在网上找不到任何关于它的信息,所以我认为它不是 Unity 的常用功能。
  • 这个问题是关于c#,而不是unityscript,这是一种完全不同的语言。

标签: c# unity3d


【解决方案1】:

我遇到了同样的问题,但是对于 IPlayerController,我刚刚删除了它并已修复 其他的我不确定

【讨论】:

    猜你喜欢
    • 2018-03-13
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-24
    • 2016-08-25
    相关资源
    最近更新 更多